【发布时间】:2016-07-01 11:33:11
【问题描述】:
如何获取位置,如显示位置之间确切路径的谷歌地图。因为它显示了直接的直线,它不包含两个地方之间的任何路径,也没有显示它通过的它们周围的位置。 我使用了以下代码:
CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocationCoordinate2DMake(51.5074, 0.1278);
coordinateArray[1] = CLLocationCoordinate2DMake(48.8566, 2.3522);
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];
对于这两个路径的连接,此代码已经实现。
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 5;
}
return self.routeLineView;
}
return nil;
}
【问题讨论】:
标签: ios iphone mkannotation apple-maps mkpolyline