简体   繁体   English

使用MapKit打开地图URL

[英]Open a map URL with MapKit

I was wondering how can I open a google map URL with MapKit ? 我想知道如何使用MapKit打开Goog​​le Map URL?

this code exit the application and shows the location but I want shows on my mapView. 此代码退出应用程序并显示位置,但我想在我的mapView上显示。

NSString *urlString = @"http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];

MapKit supports Geolocation - so how about something like this: MapKit支持地理定位-这样的事情怎么样:

CLLocation *sanFran = [CLLocation locationUsingForwardGeoLocation:@"San Francisco, Califronia"];

This returns a CLLocation which you can then show on your map view. 这会返回一个CLLocation,然后您可以在地图视图上显示它。

Have a look at the World Cities sample code (iOS dev membership required) which shows how to animate an MKMapView to coordinates. 看一下“ 世界城市”示例代码(需要iOS开发人员身份),该示例代码显示如何为MKMapView设置动画以进行坐标。

Edited to add 编辑添加

There are ways to get the Lat-long with Google Tools . 有多种方法可让您使用Google工具进行长期学习 You can use these to create a CLLocation as well. 您也可以使用它们来创建CLLocation。

You can use UIWebview to load the contents of the url. 您可以使用UIWebview加载URL的内容。 Create a webView and initialise as follows: 创建一个webView并初始化如下:

NSString *urlString = @"http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino";
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString: urlString]];
[webView loadRequest:req];

Yeah you should add this webview as a subview to your main view. 是的,您应该将此Web视图作为子视图添加到主视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM