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

标签 iphone latitude-longitude zipcode

我使用以下代码来获取 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/

相关文章:

python - 将纬度和经度转换为 3D 空间中的点

java - 查找到所选点特定距离内的所有地址的最佳方法是什么

location - 获取 n 英里半径内的所有邮政编码

jQuery 验证插件 : accept only US, 加拿大和墨西哥邮政编码?

iphone - StoreKit 沙箱测试不提示登录

iphone - 如何在 iOS 中有效地使用图像制作动画

java - Android中如何不使用getLastKnownLocation方法获取当前经纬度?

machine-learning - 如何在随机森林模型训练中最好地使用邮政编码?

iphone - AFNetworking 与 iOS 4.3 不兼容

ios - 此类与键 [Tableview 错误] 的键值编码不兼容