How to convert address (as text) to gps coordinates?

39,600

Solution 1

The process is called of converting address to geographic coordinates is called geocoding.

Depending on how you'll be using the data, there's an API available from Google, details here. Good luck!

Solution 2

It really doesn't mather which framework you use, cause if you want something big you can have a big surprise: a limit of 2.5 K request /day this in case you don't store those info in a xml for later use. So at this moment you can find a better way to combine this with a OSM feature for localization.

Solution 3

check this google map api 3 service this is the reverse-geocoding service in google map api

http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

http://googlegeodevelopers.blogspot.com/2010/03/introducing-new-google-geocoding-web.html

Solution 4

Below is the code I use. I've prepared it basing on voncox code (thanks). Just didn't want to use Zend.
If you need to geocode multiple addresses just close this code with any kind of loop but probably there is faster way. I've used it only for about 100 addresses and it took about 30 seconds to process.

$street="Lwowska 4"; $postcode="00-658"; $city="Warszawa"; $region="mazowieckie";

$a=$street.", ".$postcode.", ".$city.", ".$region;
$address = urlencode($a);
$link = "http://maps.google.com/maps/api/geocode/xml?address=".$address."&sensor=false";
$file = file_get_contents($link);

if(!$file)  {
  echo "Err: No access to Google service: ".$a."<br/>\n";
}else {
  $get = simplexml_load_string($file);

  if ($get->status == "OK") {
      $lat = (float) $get->result->geometry->location->lat;
      $long = (float) $get->result->geometry->location->lng;
      echo "lat: ".$lat."; long: ".$long."; ".$a."<br/>\n";
  }else{
    echo "Err: address not found: ".$a."<br/>\n";
  }
}
Share:
39,600
LA_
Author by

LA_

To search in your posts only type: user:me text To list all your unaccepted questions, type: user:me hasaccepted:0 My questions list: link

Updated on April 04, 2020

Comments

  • LA_
    LA_ over 4 years

    Let's say I have address as text:

    901 Cherry Ave. San Bruno, CA 94066 USA

    is there any FREE service, which can help me to identify GPS coordinates (longitude and latitude) of this address? (I'll use that in my application, so it should be some kind of API)

    The text can be in any language.