我想在我的mapView中显示一个指向点的路线,我使用此代码创建路线:
- (IBAction)backToYourCar {
MKPlacemark *sourcePlacemark = [[MKPlacemark alloc] initWithCoordinate:self.annotationForCar.coordinate addressDictionary:nil];
NSLog(@"coordiante : locationIniziale %f", sourcePlacemark.coordinate.latitude);
MKMapItem *carPosition = [[MKMapItem alloc] initWithPlacemark:sourcePlacemark];
MKMapItem *actualPosition = [MKMapItem mapItemForCurrentLocation];
NSLog(@"coordiante : source %f, ActualPosition %f", carPosition.placemark.coordinate.latitude ,actualPosition.placemark.coordinate.latitude);
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = actualPosition;
request.destination = carPosition;
request.requestsAlternateRoutes = YES;
MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
if (error) {
NSLog(@"Error : %@", error);
}
else {
[self showDirections:response]; //response is provided by the CompletionHandler …Run Code Online (Sandbox Code Playgroud) 如何启动iOS6的默认地图应用程序并将其传递给自定义位置?
例如:
[[MKMapItem setLocation:MyLocation] openInMapsWithLaunchOptions:nil];
Run Code Online (Sandbox Code Playgroud)
我按照这里的例子,但无法弄明白.如何从我自己的原生应用程序中启动Google Maps iPhone应用程序?
我正在创建一个使用CoreData存储兴趣点的应用程序.MKMapItem坐标可在其中访问mapItem.placemark.location.我想拔出个人纬度和经度坐标并将它们存储在managedObjectContext为double秒.我该怎么办?
我正试图在中显示多个位置MKMapItem.我从a获得这些位置CLGeocoder,不幸的是它只接受一个位置.即使我传入NSArray它只是返回一个位置.
以下适用于单个位置,但不适用于多个位置.如何对多个位置进行地理编码?
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
NSArray *addresses = @[@"Mumbai",@"Delhi","Banglore"];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@[addresses] completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:geocodedPlacemark.location.coordinate addressDictionary:geocodedPlacemark.addressDictionary];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:geocodedPlacemark.name];
[MKMapItem openMapsWithItems:@[mapItem] launchOptions:nil];
}];
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个使用MapKit的应用程序.我已经实现了MKLocalSearch,我得到了一个MKMapItem数组.但是我想知道是否可以获得这些项目的类别.例如,在地图应用程序中,为商店,酒店,火车站等显示了不同的图标.此外,如果您查看地点标记.您将获得一个类别标签,如Grocery.作为开发人员,我可以访问Map项目的信息吗?如果是这样,我想知道如何.
谢谢
我发现运行一些代码在地图视图中显示位置MKMapItem.openInMaps()只能在50%的时间内正常工作.
事实上,它恰好在MKPlacemark显示和不显示之间交替.
例如,代码每运行第1次,第3次,第5次,第7次,第n次显示地点标记,但每运行第2次,第4次,第6次,第8次,都会显示地点标记.
这是100%可重现的运行下面发布的代码.
这似乎是一个错误,但如果是这样,我很惊讶它以前没有被报道也没有修复过.但考虑到失败在成功和失败之间正好交替的事实导致我认为还有其他事情发生,因此我在这里张贴,看看是否有人熟悉这个问题,或者有人应该做的事情是缺失的从代码,或有一个解决方法:
override func viewDidAppear(_ animated: Bool) {
displayMap()
}
func displayMap()
{
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString("1 Infinite Loop, Cupertino,California") { (placemark: [CLPlacemark]?, error: Error?) -> Void in
if error == nil
{
if let placemark = placemark, placemark.count > 0
{
let location = placemark.first
let latitude = (location?.location?.coordinate.latitude)!
let longitude = (location?.location?.coordinate.longitude)!
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let regionDistance:CLLocationDistance = 100000
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
let options = …Run Code Online (Sandbox Code Playgroud) 我想访问MKMapItem对象中的数据。在搜索信息后,我向社区询问。根据Apple class reference,有这些属性:
如果我登录,MKMapItem我会得到显示为字典的 JSON 字典的内容,例如:
许多项目包含我想要的信息,这些信息不是MKMapItem. 有没有办法解析和建模这些项目?我试过了
NSDictionary *mapItemDictionary = (NSDictionary *)mapItem;
[mapItemDictionary valueForKey:@"key"];
Run Code Online (Sandbox Code Playgroud)
,这会导致崩溃:
[<MKMapItem 0xb02d830> valueForUndefinedKey:]:此类不符合键地址的键值编码。
所以我使用NSClassFromString检查用户是否安装了iOS 5或iOS 6以使用Apple的新iOS 6 MKMapItem.这是代码:
- (void)openDirections:(id)sender {
Class mapClass = NSClassFromString(@"MKMapItem");
if (mapClass == nil) {
// iOS 5, do something here
}
else {
// iOS 6, open up maps with MKMapItem.
}
}
Run Code Online (Sandbox Code Playgroud)
通过上面的代码,当我在iOS 5.1模拟器或iOS 5.1设备上运行它时,iOS 6分支就会运行.但是,如果我使用
Class mapClass = NSClassFromString(@"PKPass");
Run Code Online (Sandbox Code Playgroud)
这也是在iOS 6中引入的,我的代码遵循相应的iOS 5或iOS 6分支.我错过了什么吗?谢谢.
我创建了一个地图,MKPointAnnotation其中有一个地图上的单点(除了用户位置).我试图找出如何修改我现有的一些代码来获得这方面的驾驶方向.
这是我在应用程序早期使用的代码.在应用程序的早期阶段,我有以下内容,它给了我一个CLPlaceMark.
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
收集方向:
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
[request setSource:[MKMapItem mapItemForCurrentLocation]];
MKPlacemark *mkDest = [[MKPlacemark alloc] initWithPlacemark:topResult];
[request setDestination:[[MKMapItem alloc] initWithPlacemark:mkDest]];
[request setTransportType:MKDirectionsTransportTypeWalking]; // This can be limited to automobile and walking directions.
[request setRequestsAlternateRoutes:NO];
MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
if (!error) {
for (MKRoute *route in [response routes]) {
[self.mapView addOverlay:[route …Run Code Online (Sandbox Code Playgroud) mkmapitem ×9
ios ×6
mapkit ×4
iphone ×2
objective-c ×2
apple-maps ×1
clgeocoder ×1
cllocation ×1
cocoa-touch ×1
core-data ×1
ios7 ×1
json ×1
mkmapview ×1
nsdictionary ×1
swift ×1
xcode ×1
xcode5 ×1