地图使用小结(百度、google)

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

百度: 
线条绘制:
[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) {
            //循环
            }];
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、绘制多边形覆盖物(屏幕触摸点绘制多边形)


百度:
//用户点击屏幕获取经纬度
- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate
备注:需实现
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id )annotation此方法
点击大头针才回调
//点击大头针回调 
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
google
google地图点击返回坐标
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
//点击大头针回调
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
知道相应的代理实现多边形覆盖物就简单了~


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

#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);
    if (theta<0) {
        theta=360-fabs(theta)-theta1;
    }else
    {
        theta=theta-theta1;
    }
    NSLog(@"旋转角度%f",theta);
    angle1 = M_PI/180*theta;
    return angle1;
}

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

百度:
             
	     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];




你可能感兴趣的:(地图)