【问题标题】:Open iOS map with string address in Swift 2.0在 Swift 2.0 中打开带有字符串地址的 iOS 地图
【发布时间】:2016-01-05 18:08:20
【问题描述】:

我有字符串格式的地址(不是纬度或经度),从字符串中分离邮编、城市或道路名称是不可行的。

有没有可能用字符串打开地图? 字符串的格式如下: Fussballplatz Talgut, Grüzefeldstrasse , 8400 Winterthur

我尝试了两个例子: 1)http://www.techotopia.com/index.php/An_Example_Swift_iOS_8_MKMapItem_Application 这与 swift 2.0 中未定义的 kABPersonAddressStreetKey 有问题(这样想)

2) How to open maps App programmatically with coordinates in swift? 这里我没有经纬度。

【问题讨论】:

    标签: ios dictionary swift2 apple-maps


    【解决方案1】:

    我认为你应该使用CLGeocoder 类。

    这是来自苹果文档的示例: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.
             }
    }];
    

    【讨论】:

      【解决方案2】:

      看看这个问题:

      Get latitude and longitude based on Address using Geocoder class in iOS

      它有一个非常详细的答案。

      【讨论】:

        猜你喜欢
        • 2014-03-11
        • 2017-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-09
        • 2015-03-28
        • 2013-10-02
        • 2013-04-27
        相关资源
        最近更新 更多