0

I want to fetch full address by latitude and longitude in here map iOS premium sdk.In Android, I see there is the option to fetch address by latitude and longitude with ReverseGeocodeRequest but I did not find anything for iOS.

Currently, I am fetching the address from CLLocationCoordinate2D but I think it will be better if I will fetch it by HERE MAP sdk because I am using HERE MAP not Apple MAP. I have attached the android code below.

GeoCoordinate vancouver = new GeoCoordinate(latitude,longitude);

        new ReverseGeocodeRequest(vancouver).execute(new ResultListener<Location>() {

            @Override

            public void onCompleted(Location location, ErrorCode errorCode) {

                try {

                    assetData.address = location.getAddress().toString().replace("\n", "");



                } catch (NullPointerException e) {

                    e.printStackTrace();

                }



            }

        });
A.T
  • 105
  • 3
  • 13
  • You can use `CLGeocoder` to reverse (& forward) geocode. It shouldn't matter what map you then display your addresses on. https://developer.apple.com/documentation/corelocation/clgeocoder?language=objc – siburb Jun 17 '19 at 05:55
  • yes I am currently using CLGeocoder but in the android application, they are using HERE MAP Sdk for fetch location, so now both of our address is different. – A.T Jun 17 '19 at 06:09
  • Possible duplicate of [Reverse geocoding in Swift 4](https://stackoverflow.com/questions/46869394/reverse-geocoding-in-swift-4) – dahiya_boy Jun 17 '19 at 07:31
  • Obj-C : https://stackoverflow.com/questions/30255315/reverse-geocoding-using-google-maps-api-ios Google Doc : https://developers.google.com/maps/documentation/ios-sdk/reverse_geocoding – dahiya_boy Jun 17 '19 at 07:33

2 Answers2

3

You have to make use of NMAAddress class in the HERE iOS SDK.

NMAAddress provides textual address information including house number, street name, city, country, district and more. It encompasses everything about an address or a point on the map. The NMAPlaceLocation class represents an area on the map where additional attributes can be retrieved. These additional attributes include NMAAddress, unique identifier, label, location, access locations, and NMAGeoBoundingBox for the location

Please check the document section Geocoding and Reverse Geocoding for more details including sample codes.

siburb
  • 4,880
  • 1
  • 25
  • 34
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
0

You need to use Google API to fetch address from Geo Coordinates, for that please use following code

func getAddressFromLatLong(latitude: Double, longitude : Double) {
    let url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=\(latitude),\(longitude)&key=YOUR_API_KEY_HERE"

    Alamofire.request(url).validate().responseJSON { response in
        switch response.result {
        case .success:

            let responseJson = response.result.value! as! NSDictionary

            if let results = responseJson.object(forKey: "results")! as? [NSDictionary] {
                if results.count > 0 {
                    if let addressComponents = results[0]["address_components"]! as? [NSDictionary] {
                        self.address = results[0]["formatted_address"] as? String
                        for component in addressComponents {
                            if let temp = component.object(forKey: "types") as? [String] {
                                if (temp[0] == "postal_code") {
                                    self.pincode = component["long_name"] as? String
                                }
                                if (temp[0] == "locality") {
                                    self.city = component["long_name"] as? String
                                }
                                if (temp[0] == "administrative_area_level_1") {
                                    self.state = component["long_name"] as? String
                                }
                                if (temp[0] == "country") {
                                    self.country = component["long_name"] as? String
                                }
                            }
                        }
                    }
                }
            }
        case .failure(let error):
            print(error)
        }
    }
}
Asad Ali Choudhry
  • 4,985
  • 4
  • 31
  • 36
  • You certainly don't *need* to use Google Maps to reverse geocode an address from coordinates. CLGeocoder is built-in (CoreLocation), and has been able to do this since iOS5. I also believe that you're not allowed to use Google Maps to reverse geocode unless you're using their maps too. – siburb Jun 17 '19 at 10:40
  • from the first point I agree but from second I don't agree, We can still use google API call to get address from Geo Cods if we not using Google Maps. There is no issue, Above code will give you the address, just add your api key and you can get the result through http call to Google Api. – Asad Ali Choudhry Jun 17 '19 at 10:42
  • your example code is on google map api but I want it on here map sdk. – A.T Jun 17 '19 at 12:04
  • @AsadAliChoudhry I'm aware that it would technically work, but it is against Googles Terms of Service. Section 3.2.4 (e) states: `No Use With Non-Google Maps. Customer will not use the Google Maps Core Services in a Customer Application that contains a non-Google map.` [Google Maps Platform Terms of Service](https://cloud.google.com/maps-platform/terms) – siburb Jun 17 '19 at 23:36