Make a request for The Google Maps Geolocation API

∥☆過路亽.° 提交于 2019-12-22 01:37:06

问题


I would like to make a request for the web service - Google Geolocation API by using PHP 5. I have experience in XML parsing using PHP, but this one is using JSON format for making the request. I have no idea how to make the request! I think to receive the request is similar the XML parsing!

https://developers.google.com/maps/documentation/business/geolocation/


回答1:


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'));



回答2:


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


来源:https://stackoverflow.com/questions/15814609/make-a-request-for-the-google-maps-geolocation-api

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