- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location{
//实时获取经纬度
NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
//获取的经纬度
CLLocationCoordinate2D cll ={location.coordinate.latitude,location.coordinate.longitude} ;
CLLocation *towerLocation = [[CLLocation alloc] initWithLatitude:cll.latitude longitude:cll.longitude];
//放到数组集合里
[self.coordsArr addObject:towerLocation];
//声明CLLocationCoordinate2D对象
NSInteger count = [self.coordsArr count];
CLLocationCoordinate2D Coords[count];
//给CLLocationCoordinate2D添加收集的经纬度
for (int i =0; i <count; i++) {
Coords[i]=[[self.coordsArr objectAtIndex:i] coordinate];
}
//绘制你的路线
MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:Coords count:count];
[_mapView addOverlay:commonPolyline];
}
网友评论