简体   繁体   中英

How to get Coordinates from zipCode in swift

i am trying to fetch coordinates from zipcode,but getting error

{ "error_message" = "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 0.0.0.0., with empty referer"; results = ( ); status = "REQUEST_DENIED"; }

Here is my code :

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)
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM