Reputation: 115
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();
}
}
});
Upvotes: 0
Views: 3415
Reputation: 31311
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.
Upvotes: 3
Reputation: 5261
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)
}
}
}
Upvotes: 0