如何在iPhone App内的MKMapView中显示并通过带有注释的路线连接多个位置? [英] How to display and connect multiple locations with a route with annotations in an MKMapView inside an iPhone App?

查看:71
本文介绍了如何在iPhone App内的MKMapView中显示并通过带有注释的路线连接多个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示一个MKMapView,其中包含超过4个具有不同注释的位置以及连接这些位置的路线.我试图显示MKMapView内的多个位置,但仍然无法找到如何将位置与路线连接的信息.如果我以正确的方式实施它,我也试图将其检查.我创建了一个"CLLocationCoordinate2D" ,然后类似地添加了纬度和经度,得到了4点.我创建了一个自定义对象,该对象实现MKAnnotation并返回一个location.

I need to display a MKMapView with more than 4 locations with different Annotations and a route connecting the locations. I have tried to display the multiple locations inside a MKMapView but i still not able to find out on how to connect the locations with a route. I am also trying to get this checked if i have implemented it in a right way. I have created a "CLLocationCoordinate2D" and then added a lat and long similarly for 4 points. I have created a custom object which implements MKAnnotation and returning a location .

CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake(40.7180583 ,-74.007109);
CLLocationCoordinate2D coordinate2 = CLLocationCoordinate2DMake(40.716355 ,-74.006816);
CLLocationCoordinate2D coordinate3 = CLLocationCoordinate2DMake(40.715281 ,-74.005485);
CLLocationCoordinate2D coordinate4 = CLLocationCoordinate2DMake(40.71559 ,-74.003114);

AnnotationPoints *location1 = [[AnnotationPoints alloc] initWithCoordinate:coordinate1];
AnnotationPoints *location2 = [[AnnotationPoints alloc] initWithCoordinate:coordinate2];
AnnotationPoints *location3 = [[AnnotationPoints alloc] initWithCoordinate:coordinate3];
AnnotationPoints *location4 = [[AnnotationPoints alloc] initWithCoordinate:coordinate4];

NSArray *poiArray = [[NSArray alloc] initWithObjects:location1,location2,location3,location4,nil];
    [mapView addAnnotations:poiArray];

//Inside the Annotation Class initWithCoordinate Method is implemented this way:-
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
    coordinate=c;
    NSLog(@"%f,%f",c.latitude,c.longitude);
    return self;
}

我在这里的担心是我需要为每个位置创建一个注释点.有没有其他选择可以将所有点加载到一个地方.这里的另一个困难是连接所有多个点的路线.有什么帮助吗?非常感谢

My concern here is i need to create a Annotation Point for every Location. Is there any alternative that i can load all the points at a single place. And another difficulty here is the route connecting all the multiple points. Any help on this? Thanks a lot

推荐答案

添加批注的方式很好.
不知道您的关注点是什么,以及所有地方都在一个地方"意味着什么.
如果要在多个位置使用图钉/注释,则必须为每个位置创建一个单独的注释对象.

The way you are adding the annotations is fine.
Not sure what your concern is and what you mean by "all the points at a single place".
If you want pins/annotations at several places, you have to create a separate annotation object for each place.

绘制连接这些位置的路线需要创建一个覆盖图(而不是注释").
您想在地图上添加MKPolyline,以为其指定坐标列表.

Drawing a route connecting those locations requires creating an overlay (not an "annotation").
You want to add an MKPolyline to the map for which you will specify the list of coordinates.

要绘制折线,不需要在每个坐标处都添加注释(但是如果需要的话也可以).

To draw the polyline, you don't need to also add annotations at each coordinate (but you could if you want to).

创建和添加MKPolyline及其对应的MKPolylineViewMKPolygonMKPolygonView非常相似.参见以下问题的示例:

Creating and adding an MKPolyline and its corresponding MKPolylineView is very similar to MKPolygon and MKPolygonView. See this question for an example:

iPhone MKMapView-MKPolygon问题

这篇关于如何在iPhone App内的MKMapView中显示并通过带有注释的路线连接多个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆