newCoor= malloc(sizeof(CLLocationCoordinate2D) * 2);
#pragma mark -- CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
if (locations != nil && locations.count > 0)
{
NSLog(@"位置信息:%@",manager.location);
newMapLocation=manager.location;
//当前位置
CLLocation *newLocation=locations[0];
//判断在中国地图上
// if ([WGS84TOGCJ02 isLocationOutOfChina:[newLocation coordinate]]) {
// return;
// }
//转换后的coord
CLLocationCoordinate2D newCoordinate = [WGS84TOGCJ02 transformFromWGSToGCJ:[newLocation coordinate]];
if (newCoor==NULL) {
newCoor[0]=newLocation.coordinate;
}else
{
newCoor[1]=newLocation.coordinate;
MKMapPoint newPoint = MKMapPointForCoordinate(newLocation.coordinate);
// 得到两点的距离
MKMapPoint prevPoint = MKMapPointForCoordinate(newCoor[0]);
CLLocationDistance metersApart = MKMetersBetweenMapPoints(newPoint, prevPoint);
if (metersApart>10) {
speed=newLocation.speed;
MKPolyline *crum=[MKPolyline polylineWithCoordinates:newCoor count:2];
[map addOverlay:crum level:MKOverlayLevelAboveRoads];
newCoor[0]=newLocation.coordinate;
}
}
}
realloc(newCoor, sizeof(CLLocationCoordinate2D)*2);
}- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
MKOverlayRenderer *renderer = nil;
MKPolylineRenderer *line=[[MKPolylineRenderer alloc]initWithOverlay:overlay];
line.lineWidth=10;
[line setStrokeColor:[UIColor redColor]];
renderer=line;
return renderer;
}
本文探讨了如何在地图应用中实时更新位置并绘制路径的技术实现,包括位置信息处理、坐标转换、距离计算和地图覆盖物的动态更新。

1042

被折叠的 条评论
为什么被折叠?



