我使用以下代码使用以下代码
获取特定地点在地图上的位置NSString * urlString = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps/geo?key=%@&output=xml&q=%@",GoogleMapsAPIKey,[placeName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
结果:
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>postdam</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>Potsdam, Germany</address>
<AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Brandenburg</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Potsdam</SubAdministrativeAreaName><Locality><LocalityName>Potsdam</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="52.4513968" south="52.3424614" east="13.1866602" west="12.9305414" />
</ExtendedData>
<Point><coordinates>13.0586008,52.3969627,0</coordinates></Point>
</Placemark>
</Response></kml>
但现在我想获得有关邮政编码的信息。如何使用maps.google.com?
答案 0 :(得分:1)
您不再需要使用google maps API密钥来访问此API。
下面是我昨天写的一个PHP函数,用于在JSON中实现这一功能
function getCoordinatesFromAddress($address, $lat, $long, $region="US") {
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
}
答案 1 :(得分:0)
由于谷歌地图以美国为中心,只需直接输入邮政编码即可(至少暂时)
http://maps.google.com/maps/geo?output=xml&q=90210
<AdministrativeArea>
<AdministrativeAreaName>CA</AdministrativeAreaName>
<SubAdministrativeArea>
<SubAdministrativeAreaName>Los Angeles</SubAdministrativeAreaName>
<Locality>
<LocalityName>Beverly Hills</LocalityName>
<PostalCode>
<PostalCodeNumber>90210</PostalCodeNumber>
</PostalCode>
</Locality>
</SubAdministrativeArea>
</AdministrativeArea>