请求Google地图地理位置API [英] Make a request for The Google Maps Geolocation API

查看:94
本文介绍了请求Google地图地理位置API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过PHP 5请求Web服务 - Google Geolocation API。我有使用PHP进行XML解析的经验,但是这是使用JSON格式提出请求的。我不知道如何提出请求!我认为接收请求与XML解析类似!

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://开发人员.google.com / maps / documentation / business / geolocation /

推荐答案

试试这个(导致json格式) :

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

这篇关于请求Google地图地理位置API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆