【问题标题】:How to get Coordinates from zipCode in swift如何快速从邮政编码获取坐标
【发布时间】:2018-05-16 10:22:52
【问题描述】:

我正在尝试从邮政编码获取坐标,但出现错误

{ "error_message" = "此 IP、站点或移动应用程序无权使用此 API 密钥。从 IP 地址收到请求 0.0.0.0.,引用者为空"; 结果 = ( ); status = "REQUEST_DENIED"; }

这是我的代码:

public func getLocationFromAddress(zipCode : String) -> CLLocationCoordinate2D {
    let lat : Double = 0.0
    let lon : Double = 0.0        
    let strUrl = "https://maps.googleapis.com/maps/api/geocode/json?address=\(zipCode)&key=\(Global.kGoogleApiKey.strPlaceAPIKey)&sensor=false"
    let escapedString = strUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)

    AFAPIMaster.sharedAPIMaster.getLatLongCallApi_Completion(strGetURL:escapedString!,params: nil, showLoader: true, enableInteraction: false, viewObj:self.view, onSuccess: { (result) in
      if let Dict = result as? NSDictionary {
        print(Dict)
      }
    }, onFailure: { })
    return CLLocationCoordinate2D(latitude: lat, longitude: lon)
}

【问题讨论】:

  • 您使用的 API 密钥不起作用
  • 我必须创建服务器密钥?

标签: ios swift google-maps


【解决方案1】:

您必须为您的移动应用程序创建一个带有捆绑 ID 的 Api_key 才能使用该地理编码

【讨论】:

  • 如何创建服务器密钥
  • 索要账单
猜你喜欢
  • 1970-01-01
  • 2013-04-05
  • 1970-01-01
  • 1970-01-01
  • 2012-10-18
  • 1970-01-01
  • 2016-11-23
  • 2010-10-29
  • 1970-01-01
相关资源
最近更新 更多