地图绘制线条(百度与google差异)

1、轨迹回放:线条绘制与点到点动画

1
2
3
4
5
6
7
8
9
10
//百度地图线条绘制:
[BMKPolyline setPolylineWithCoordinates:coor count:count];
//动画:
[UIView animateWithDuration:node.distance/30/timeFloat animations:^{
currentIndex++;
BMKSportNode *node = [sportNodes objectAtIndex:currentIndex ];
BMKPointAnnotation.coordinate = node.coordinate;
} completion:^(BOOL finished) {
//循环
}];
1
2
3
4
5
6
7
8
9
10
11
12
//google地图绘制线条:
GMSMutablePath *path = [GMSMutablePath path];
GMSPolyline.path=path;
//动画:与百度不一样,使用[UIView animateWith] 无动画效果,没深究,然后使用CATransaction动画 加定时器
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:node1.distance/30/timeFloat] forKey:kCATransactionAnimationDuration];
gmsMarker.position = node.coordinate;
[CATransaction commit];
google地图移除覆盖物线条标注
self.map=nil

//(google动画无效果原因google大头针继承NSObject,所以使用CATransaction)

2、绘制多边形覆盖物(屏幕触摸点绘制多边形)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//百度:
//用户点击屏幕获取经纬度
- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate
备注:需实现
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation此方法
//点击大头针才回调
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view

//google地图点击返回坐标
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate

//点击大头针回调
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
//知道相应的代理实现多边形覆盖物就简单了~

3、点到点旋转角度 距离计算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma mark -- 两点距离角度计算
-(double)distanceBetweenPoints:(CLLocationCoordinate2D)startCoor endCoor:(CLLocationCoordinate2D)endCoor
{
double sx=startCoor.latitude;
double sy=startCoor.longitude;
double ex=endCoor.latitude;
double ey=endCoor.longitude;

return sqrt(fabs(ex-sx)*fabs(ex-sx)+fabs(ey-sy)*fabs(ey-sy));
}
-(double)calcAngleStrtCoor:(CLLocationCoordinate2D)startCoor endCoor:(CLLocationCoordinate2D)endCoor
{
//角度时钟0点计算旋转
double sx=startCoor.latitude;
double sy=startCoor.longitude;
double ex=endCoor.latitude;
double ey=endCoor.longitude;
NSLog(@"start %f,%f",sx,sy);
double angle1= (atan2((ey-sy), (ex-sx)));
double theta= angle1 *(180/M_PI);
NSLog(@"%f",theta);
double theta1=90;
NSLog(@"上一个角度%f",theta1);
i f (theta<0) {
theta=360-fabs(theta)-theta1;
}else
{
theta=theta-theta1;
}
NSLog(@"旋转角度%f",theta);
angle1 = M_PI/180*theta;
return angle1;
}

4、根据GPS坐标 反地理编码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//百度
geoCodeSearch = [[BMKGeoCodeSearch alloc] init];
geoCodeSearch.delegate = self; BMKReverseGeoCodeOption *reverseGeoCodeOption= [[BMKReverseGeoCodeOption alloc] init];
reverseGeoCodeOption.reverseGeoPoint = coor;
[geoCodeSearch reverseGeoCode:reverseGeoCodeOption];
//BMKGeoCodeSearchDelegate
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error {
//result 位置信息
}



//google
GMSReverseGeocodeCallback callBack = ^(GMSReverseGeocodeResponse *response, NSError *error) {
if(error == nil) {
GMSAddress *firstResult = response.firstResult;
NSString *country = firstResult.country;
NSString *administrativeArea = firstResult.administrativeArea;
NSString *locality = firstResult.locality;
NSString *subLocality = firstResult.subLocality;
NSString *thoroughfare = firstResult.thoroughfare;
}
};
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:coor completionHandler:callBack];