2017-06-03 28 views
-1

我已經搜索了互聯網,但無法找到我是否可以從緯度和經度獲取地圖圖像。iOS - 爲經度和緯度生成地圖圖像

是否有任何API可以給我的地圖圖像。 因爲我得到了開始位置和結束位置。

當我給出開始和結束的位置,它應該給我地圖圖像的路線。 是可能的。

如果我在mapview上,我可以管理快照,但是在這裏我不會有任何mapview。

任何鏈接,想法,建議高度讚賞。

問候。

回答

1

我不知道是否有任何API可用於此,但是當我這樣做時,我只需撥打Apple Maps應用程序並提供一個latitudelongitude作爲我的位置並打開該應用程序。

通過這種方式,用戶可以使用蘋果的地圖應用程序來瀏覽和獲取有關道路等全部信息

這裏是我稱之爲:

func navigateWithAppleMaps(latitude: Double, longitude: Double) { 
    let regionDistance:CLLocationDistance = 10000 
    let coordinates = CLLocationCoordinate2DMake(latitude, longitude) 
    let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance) 
    let options = [ 
     MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), 
     MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span) 
    ] 
    let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil) 
    let mapItem = MKMapItem(placemark: placemark) 
    mapItem.name = "Start" 
    mapItem.openInMaps(launchOptions: options) 
} 
+0

我希望地圖圖像顯示在我的地圖歷史表格單元格中。 ,因爲我不能初始化映射到每個tableview單元格 – user3804063

1

您可以從剛纔路過的經度和緯度,從下面的鱈魚獲得圖像即您可以在URL中的mapview上設置縮放比例。

var staticMapUrl: String = "http://maps.google.com/maps/api/staticmap?markers=color:red|\(YOUR LATITUDE HERE),\(YOUR LONGITUDE HERE)&\("zoom=16&size=400x400")&sensor=true" 
var mapUrl = URL(string: staticMapUrl.addingPercentEscapes(using: String.Encoding.utf8)) 
var image = UIImage(data: Data(contentsOf: mapUrl)) 
+0

至少我可以從我的經緯度中獲得圖像。但我需要獲得兩個地點之間的路線。你能幫助更多嗎? :) :) – user3804063

+0

你不能得到這種類型的圖像。爲此,你必須使用谷歌地圖API –

+0

與谷歌地圖API,你可以很容易地跟蹤兩個位置之間的方向 –