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

随声附和 提交于 2020-01-01 04:18:28

问题


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.


回答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!




回答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.




回答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




回答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";
  }
}



回答5:


If you are able/willing to use php and Zend Framework then most of the Google Maps API is abstracted by using Zend_Http_Client.

For example:

$address = '69 Some Road, Somewhere, NW1 8UJ';

$http = new Zend_Http_Client('google_maps_url');
$http->setParameterGet(array('address' => $address, 'sensor' => 'false'));
$get = $http->request();
$get = json_decode($get->getBody());

if ($get->status == self::GOOGLE_MAPS_SUCCESS) {
    $lat = (float) $get->results[0]->geometry->location->lat;
    $long = (float) $get->results[0]->geometry->location->lng;
}



回答6:


FYI, MapQuest's Community License has an 'open' api, which uses nominatim / OpenStreetMap on the backside.

It is the same API (interface-wise) as the Community 'Licensed' api, which makes it easy to transition later.

I found that the open version requires the address to be a little too exact; on the first day after deployment we "missed" several addresses. We thought the service was down, but it turns out the street names were missing little details such as a direction (ex SW).

Tried out the Licensed version, and it returned even the misspelled addresses.

The Community license licensed data version is free also, but are restricted by pretty much the same terms as the Google one. The 'open' data you can do with what you want.

If you are going to end up paying, then Yahoo's Boss/Geo api seems to be the cheapest for low volume; they just don't have a free version.



来源:https://stackoverflow.com/questions/6996577/how-to-convert-address-as-text-to-gps-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!