Make a request for The Google Maps Geolocation API

…衆ロ難τιáo~ 提交于 2019-12-04 21:39:42

try this(result in json format):

public function getGeoPosition($address){
    $url = "http://maps.google.com/maps/api/geocode/json?sensor=false" . 
        "&address=" . urlencode($address);

    $json = file_get_contents($url);

    $data = json_decode($json, TRUE);

     if($data['status']=="OK"){
      return $data['results'];
    }

}

print_r(getGeoPosition('chicago,il'));

If you have a Business account ,as suggested by your link, Google supply help. If you don't have a business account you would will need to use use This API which provides xml results. ie

 http://maps.googleapis.com/maps/api/geocode/xml?address=anywhere&sensor=true

or

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