相关疑难解决方法(0)

如何用swift中的坐标以编程方式打开地图App?

我有经度和经度,我想打开我的地图应用程序.我从这里试过这段代码.

    func goToMap(){

    var lat1 : NSString = self.venueLat
    var lng1 : NSString = self.venueLng

    var latitude:CLLocationDegrees =  lat1.doubleValue
    var longitude:CLLocationDegrees =  lng1.doubleValue

    var coordinate = CLLocationCoordinate2DMake(latitude, longitude)

    var placemark : MKPlacemark = MKPlacemark(coordinate: coordinate, addressDictionary:nil)

    var mapItem:MKMapItem = MKMapItem(placemark: placemark)

    mapItem.name = "Target location"

    let launchOptions:NSDictionary = NSDictionary(object: MKLaunchOptionsDirectionsModeDriving, forKey: MKLaunchOptionsDirectionsModeKey)

    var currentLocationMapItem:MKMapItem = MKMapItem.mapItemForCurrentLocation()

    MKMapItem.openMapsWithItems([currentLocationMapItem, mapItem], launchOptions: launchOptions)

}
Run Code Online (Sandbox Code Playgroud)

此功能可以成功打开地图,但不会显示任何图钉.它还显示了我不想要的用户位置.我只想在地图上找到所提供纬度和经度的图钉.

ios apple-maps swift

96
推荐指数
6
解决办法
8万
查看次数

标签 统计

apple-maps ×1

ios ×1

swift ×1