如何在MKMapview上跟踪用户位置并在用户路径上画线 [英] How to trace users location on MKMapview and draw line on users path
问题描述
当用户单击地图上的按钮并沿着该路径绘制一条蓝线或红线时,我想在mapView上跟踪我的用户路径,如下图所示.我也想测量用户的行进距离.目前,我正在使用MKMapView.使用iOS地图套件可以完成此任务吗?还是我应该继续使用Google Maps SDK.我刚刚开始学习iOS开发,如果您发现问题不对,请多多包涵. 预先感谢...;)
I would like to trace my users path on mapView when the user clicks a button on the map and draw a blue or red line along the path like shown in the image below. Also I would like to measure the distance traveled by the user. Currently I am using MKMapView. Is this task possible with iOS map kit or should i move on to using Google maps SDK. I've just started learning iOS development please bear with me if you find the question out of order. Thanks in advance...;)
推荐答案
google ios sdk
https ://developers.google.com/maps/documentation/ios/遵循此步骤.
#import <GoogleMaps/GoogleMaps.h>
#import "DemoViewController.h"
@implementation DemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0
longitude:-165
zoom:2];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-33.866 longitude:151.195]; // Sydney
[path addLatitude:-18.142 longitude:178.431]; // Fiji
[path addLatitude:21.291 longitude:-157.821]; // Hawaii
[path addLatitude:37.423 longitude:-122.091]; // Mountain View
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor blueColor];
polyline.strokeWidth = 5.f;
polyline.map = mapView;
self.view = mapView;
}
@end
这篇关于如何在MKMapview上跟踪用户位置并在用户路径上画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!