Я новичок в разработке iOS. я использую Google Map sdk для получения местоположения из MapView. Я получил текущее местоположение. Как широта и долгота, но теперь я хочу получить текущий адрес с почтовым индексом. От широты и долготы, как это возможно, пожалуйста, дайте мне решение для этого.Как использовать обратное Google GeoCoding в iOS?
0
A
ответ
0
Вы можете использовать CLGeocoder
и reverseGeocodeLocation:completionHandler:
метод:
- (void)getAddressFromLocation:(CLLocation *)location completionHandler:(void (^)(NSMutableDictionary *placemark))completionHandler failureHandler:(void (^)(NSError *error))failureHandler
{
NSMutableDictionary *d = [NSMutableDictionary new];
CLGeocoder *geocoder = [CLGeocoder new];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if (failureHandler && (error || placemarks.count == 0)) {
failureHandler(error);
} else {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
if(completionHandler) {
completionHandler(placemark.addressDictionary);
}
}
}];
}
И называют это так:
// Your location from latitude and longitude
CLLocation *location = [[CLLocation alloc] initWithLatitude:aLatitude longitude:aLongitude];
// Call the method to find the address
[self getAddressFromLocation:location completionHandler:^(NSMutableDictionary *d) {
NSLog(@"address informations : %@", d);
NSLog(@"formatted address : %@", [placemark.addressDictionary valueForKey:@"FormattedAddressLines"]);
NSLog(@"Street : %@", [d valueForKey:@"Street"]);
NSLog(@"ZIP code : %@", [d valueForKey:@"ZIP"]);
NSLog(@"City : %@", [d valueForKey:@"City"]);
// etc.
} failureHandler:^(NSError *error) {
NSLog(@"Error : %@", error);
}];
0
Вы можете использовать CLGeocoder:
__block CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:theLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
DDLogVerbose(@"Geocode failed with error: %@", error);
if([self.delegate respondsToSelector:@selector(geocodeFailed:)]) {
[self.delegate geocodeFailed:error];
}
return;
}
MKPlacemark *placemark = [placemarks lastObject];
if(placemark) {
NSArray *shortDescArray = [placemark.addressDictionary valueForKey:@"FormattedAddressLines"];
NSString *shortDesc = [shortDescArray componentsJoinedByString:@", "];
DDLogVerbose(@"myPlacemark %@", placemark.addressDictionary);
} else {
DDLogVerbose(@"Geocode failed");
}
}];
Смежные вопросы
- 1. Приложения для iOS и API Google Geocoding
- 2. Google Maps iOS Обратное геокодирование
- 3. google обратное геокодирование api без карт google
- 4. postalCode получил (null) в iOS Google Maps SDK обратное геокодирование
- 5. Google GeoCoding Query
- 6. API Google Geocoding - Уведомления
- 7. Google Geocoding API/Google earth
- 8. Google Geocoding Api "OVER_QUERY_LIMIT"
- 9. API Google Geocoding
- 10. Google Maps GeoCoding ... INVALID_REQUEST?
- 11. Google Geocoding $ .ajax()
- 12. API Google Geocoding request_denied
- 13. Googlemaps Обратное GeoCoding Получить название страны, страны Великобритании
- 14. Google Geocoding Weirdness
- 15. Google iOS Geocoding SDK reverse lat long to Places ID
- 16. Google GeoCoding всегда возвращает ошибку
- 17. Как использовать поиск POI/Geocoding в skobbler
- 18. Использование Google Geocoding с Python
- 19. Проблемы с Google Reverse geocoding
- 20. google maps ios sdk geocoding запрос возвращает только 1 результат
- 21. Увеличьте пределы API Google GeoCoding
- 22. Адрес (обратное геокодирование) google maps
- 23. Как сделать обратное наложение на карте Google?
- 24. Geocoding в R с Google Maps
- 25. Поддержка gzip-ответа от Google Geocoding API
- 26. IOS7 API Google Maps Reverse Geocoding xCode
- 27. Геокодирование и обратное кодирование в iOS с использованием Google Maps
- 28. google maps - обратное геокодирование
- 29. Google maps geocoding не возвращает местоположение
- 30. Google Maps Reverse Geocoding возвращает только «APPROXIMATE»
Я хочу Fetch Некоторый data From This addressDictionary как CityName, Address, Street adesss, Zipcode и т. д. как его получить? – Ramesh
Объект MKPlacemark имеет 'addressDictionary', который вы можете получить через' valueForKey': NSArray * shortDescArray = [placemark.addressDictionary valueForKey: @ "FormattedAddressLines"]; –