地图共享应用程序中的 Google 地图方向可提供个性化注释
我创建了一个应用程序,它使用自定义图钉在自定义地图上显示不同的点,并使用公开按钮显示标题和副标题(好吧)。当应用程序启动地图来创建路径然后提供方向时,就会出现问题。要从用户的位置移动,我只需输入 URL“saddr=当前位置”。当我尝试给出用户触摸的相对于触摸的引脚的目的地时,问题就出现了。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f%1.6f&saddr=Posizione Attuale", mapView.annotations.coordinate.latitude mapView.annotations.coordinate.longitude];
//另外mapview.annotation.coordinate.latitude/longitude不起作用
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
我不知道如何在代码段中传递注释的坐标!
这是我所说的并将注释添加到我的视图中
NSMutableArray* annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 45.7;
theCoordinate1.longitude = 7.64;
myAnnotation* myAnnotation1=[[myAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate1;
myAnnotation1.title=@"Pippo";
myAnnotation1.subtitle=@"Ufficio";
[myMapView addAnnotation:myAnnotation1];
这对具有不同名称(myAnnotation1、2、3、4)和坐标其他的 4 个要点重复!当用户点击1-2-3或4移动到正确的目的地时该怎么办?
提前致谢! :)
I created an app that displays different points on a custom map with custom pins and showing the title and subtitle with a disclosure button (all right). The problem arises when the app launches maps to create the path and then provide directions. To move from the position of the user I've simply typed in the URL "saddr=Current Position". The problem comes when I try to give the destination that the user has touched, relative to the pin touched.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f%1.6f&saddr=Posizione Attuale", mapView.annotations.coordinate.latitude mapView.annotations.coordinate.longitude];
//also mapview.annotation.coordinate.latitude/longitude doesn't work
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
I can not figure out how to pass the coordinates of the annotation in the piece of code!
Here's how I said and added the annotation to my view
NSMutableArray* annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 45.7;
theCoordinate1.longitude = 7.64;
myAnnotation* myAnnotation1=[[myAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate1;
myAnnotation1.title=@"Pippo";
myAnnotation1.subtitle=@"Ufficio";
[myMapView addAnnotation:myAnnotation1];
This repeated for 4 main points that have different names (myAnnotation1, 2, 3, 4) and coordinates other! How can I do when the user touches 1-2-3 or 4 to move the right destination?
Thanks in advance! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
calloutAccessoryControlTapped
中,为什么要推送一个空白视图控制器并同时调用openURL
?无论如何,注释的坐标位于
view.annotation.coordinate
中。因此,纬度为
view.annotation.coordinate.latitude
,经度为view.annotation.coordinate.longitude
。此外,在您的
addr
字符串中,坐标之间缺少逗号。In
calloutAccessoryControlTapped
, why are you pushing a blank view controller and callingopenURL
at the same time?Anyway, the annotation's coordinates are in
view.annotation.coordinate
.So the latitude is
view.annotation.coordinate.latitude
and longitude isview.annotation.coordinate.longitude
.Also, in your
addr
string, you are missing a comma between the coordinates.