gpt4 book ai didi

iphone - 根据邮政编码获取某个地点的纬度和经度

转载 作者:行者123 更新时间:2023-12-03 21:23:27 26 4
gpt4 key购买 nike

我使用以下代码来获取 map 上特定地点的位置

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 做到这一点?

最佳答案

您不再需要使用 Google map API key 来访问此 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&region=$region");
$json = json_decode($json);

$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
}

关于iphone - 根据邮政编码获取某个地点的纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2728582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com