谷歌地图API的Web Service参数

谷歌地图API的Web Service参数

问题描述:

我试图使用地理编码新的API在https://maps.googleapis.com/maps/api/geocode/json?address=Chiavari+Via+Preli+30&key= ....谷歌地图API的Web Service参数

我有一个关于它的几个问题:

  1. 我感兴趣的一个仅仅是关于经度和纬度的信息。 我如何分离这些信息? (我需要将它添加到一个php 脚本)
  2. 有没有一种方法(网络服务参数)只得到我需要的?
  3. 使用这个网络服务,是否有可能计算从 2点不仅作为一条线,但也作为一条道路的距离?
+0

发现这对JS --- 为(I = 0;我 Graziano

使用json_decode($json_string)将json字符串转换为变量。

http://php.net/manual/en/function.json-decode.php

$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=Apple%20inc&key='); 
$data = json_decode($json); 

foreach($data->results as $result) { 

    print '<h4>' . $result->formatted_address . '</h4>'; 
    print 'Lat: ' . $result->geometry->location->lat . ', ' . $result->geometry->location->lng . '<hr>'; 
} 

print '<pre>'; 
print_r($data); 
print '</pre>'; 
+0

嗨..我用simplexml_load_file而不是file_get_content。我对xml更感兴趣......它可以工作......有时候......例如 - $ xml = simplexml_load_file($ google_url)或die(“url not loading”); echo“googleurl - >”。 $ google_url。 “
”; print_r($ xml); - 它适用于90%的请求...但有时它不工作,并不明白为什么... 如果我通过(例如)网址... https://maps.googleapis。 com/maps/api/geocode/xml?address =LocalitàPeziè,118,32043 CORTINA D'AMPEZZO,Italia&key = 结果是INVALID_REQUEST ...如果我复制并粘贴到浏览器中,它正常工作...为什么? – Graziano

+0

ps ..如何发布格式化的代码? – Graziano

+0

btw解决了最后...问题是由于在意大利语特殊字符 – Graziano