Откройте карту iOS со строковым адресом в Swift 2.0

У меня есть адрес в формате строки (не широта и не долгота), и невозможно отделить от строки почтовый индекс, название города или дороги.

Есть ли возможность открыть карту строкой? Строка имеет следующий формат: Fussballplatz Talgut, Grüzefeldstrasse, 8400 Winterthur.

Я попробовал два примера: 1) http://www.techotopia.com/index.php/An_Example_Swift_iOS_8_MKMapItem_Application у этого есть проблема с kABPersonAddressStreetKey, который не определен в swift 2.0 (думаю, да)

2) Как программно открыть приложение карт с координатами в Swift ? здесь у меня нет широты или долготы.


person Vannian    schedule 08.10.2015    source источник


Ответы (2)


Я думаю, вам следует использовать класс CLGeocoder.

Это пример из документации Apple: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html:

    /*
     Use the CLGeocoder class with a dictionary of Address Book
     information or a simple string to initiate forward-geocoding          
     requests. There is no designated format for string-based 
     requests: Delimiter characters are welcome, but not required, 
     and the geocoder server treats the string as case-insensitive. 
     For example, any of the following strings would yield results:

    "Apple Inc”
    "1 Infinite Loop”
    "1 Infinite Loop, Cupertino, CA USA” 
   */
[geocoder geocodeAddressString:@"1 Infinite Loop"
     completionHandler:^(NSArray* placemarks, NSError* error){
         for (CLPlacemark* aPlacemark in placemarks)
         {
             // Process the placemark.
         }
}];
person Francis Yeap    schedule 08.10.2015

взгляните на этот вопрос:

Получите широту и долготу на основе адреса, используя Класс геокодера в iOS

у него есть довольно подробный ответ.

person dirtydanee    schedule 08.10.2015