How to Get Address in English Language Only Using Gmsgeocoder

How to obtain country, state, city from reverseGeocodeCoordinate?

The simplest way is to upgrade to Version 1.7 of the Google Maps SDK for iOS (released February 2014).

From the release notes:

GMSGeocoder now provides structured addresses via GMSAddress, deprecating GMSReverseGeocodeResult.

From GMSAddress Class Reference, you can find these properties:

coordinate
Location, or kLocationCoordinate2DInvalid if unknown.

thoroughfare
Street number and name.

locality
Locality or city.

subLocality
Subdivision of locality, district or park.

administrativeArea
Region/State/Administrative area.

postalCode
Postal/Zip code.

country
The country name.

lines
An array of NSString containing formatted lines of the address.

No ISO country code though.

Also note that some properties may return nil.

Here's a full example:

[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(40.4375, -3.6818) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
NSLog(@"reverse geocoding results:");
for(GMSAddress* addressObj in [response results])
{
NSLog(@"coordinate.latitude=%f", addressObj.coordinate.latitude);
NSLog(@"coordinate.longitude=%f", addressObj.coordinate.longitude);
NSLog(@"thoroughfare=%@", addressObj.thoroughfare);
NSLog(@"locality=%@", addressObj.locality);
NSLog(@"subLocality=%@", addressObj.subLocality);
NSLog(@"administrativeArea=%@", addressObj.administrativeArea);
NSLog(@"postalCode=%@", addressObj.postalCode);
NSLog(@"country=%@", addressObj.country);
NSLog(@"lines=%@", addressObj.lines);
}
}];

and its output:

coordinate.latitude=40.437500
coordinate.longitude=-3.681800
thoroughfare=(null)
locality=(null)
subLocality=(null)
administrativeArea=Community of Madrid
postalCode=(null)
country=Spain
lines=(
"",
"Community of Madrid, Spain"
)

Alternatively, you may consider using Reverse Geocoding in the The Google Geocoding API (example).

GMSServices GMSGeocoder reverseGeocodeCoordinate language of returned results in IOS

Copy paste answer from stackoverflow.com/a/24333593/4195406

In - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

add

NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
if (![[languages firstObject] isEqualToString:@"en"]) {
[[NSUserDefaults standardUserDefaults] setObject:@[@"en"] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

This works for me

Flutter - Get geocode address from coordinates

Update:
Use geocoding

import 'package:geocoding/geocoding.dart';

List<Placemark> placemarks = await placemarkFromCoordinates(52.2165157, 6.9437819);

Old solution:

You are already there, extra stuff that you need is:

String _address = ""; // create this variable

void _getPlace() async {
List<Placemark> newPlace = await _geolocator.placemarkFromCoordinates(_position.latitude, _position.longitude);

// this is all you need
Placemark placeMark = newPlace[0];
String name = placeMark.name;
String subLocality = placeMark.subLocality;
String locality = placeMark.locality;
String administrativeArea = placeMark.administrativeArea;
String postalCode = placeMark.postalCode;
String country = placeMark.country;
String address = "${name}, ${subLocality}, ${locality}, ${administrativeArea} ${postalCode}, ${country}";

print(address);

setState(() {
_address = address; // update _address
});
}

How to force language in which reverse geocoding data on iOS is received?

You can not force the language of the geo data retrieved from CLGeocoder or MKReverseGeocoder. It will always be the system language of the device.
If you want to get the data in English you need to built your own geocoder which is relatively easy to implement with the Google Maps API.

Here is a spreadsheet of the supported languages in Google Maps API:
https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1

Swift - Generate an Address Format from Reverse Geocoding

func getAddressFromLatLon(pdblLatitude: String, withLongitude pdblLongitude: String) {
var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
let lat: Double = Double("\(pdblLatitude)")!
//21.228124
let lon: Double = Double("\(pdblLongitude)")!
//72.833770
let ceo: CLGeocoder = CLGeocoder()
center.latitude = lat
center.longitude = lon

let loc: CLLocation = CLLocation(latitude:center.latitude, longitude: center.longitude)

ceo.reverseGeocodeLocation(loc, completionHandler:
{(placemarks, error) in
if (error != nil)
{
print("reverse geodcode fail: \(error!.localizedDescription)")
}
let pm = placemarks! as [CLPlacemark]

if pm.count > 0 {
let pm = placemarks![0]
print(pm.country)
print(pm.locality)
print(pm.subLocality)
print(pm.thoroughfare)
print(pm.postalCode)
print(pm.subThoroughfare)
var addressString : String = ""
if pm.subLocality != nil {
addressString = addressString + pm.subLocality! + ", "
}
if pm.thoroughfare != nil {
addressString = addressString + pm.thoroughfare! + ", "
}
if pm.locality != nil {
addressString = addressString + pm.locality! + ", "
}
if pm.country != nil {
addressString = addressString + pm.country! + ", "
}
if pm.postalCode != nil {
addressString = addressString + pm.postalCode! + " "
}

print(addressString)
}
})

}


Related Topics



Leave a reply



Submit