使用谷歌地图自定义MapView(iOS)

时间:2015-02-13 11:03:24

标签: ios iphone

我必须做自定义MapView,我已经用当前位置完成了半径为1000米的mkCircle。

但是我没有得到如何拖动半径圆。

-(void)viewDidAppear:(BOOL)animated
{
    if(![CLLocationManager locationServicesEnabled])
    {
        NSLog(@"You need to enable location services to use this app");
        UIAlertView *errorAlert = [[UIAlertView alloc]
                                   initWithTitle:@"Error" message:@"Enable Location Services" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
        return;
    }

    if(self.locationManager==nil)
    {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        self.locationManager.pausesLocationUpdatesAutomatically=NO;

        NSString *version = [[UIDevice currentDevice] systemVersion];
        if([version floatValue] > 7.0f)
        {
            if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
            {

                [self.locationManager requestAlwaysAuthorization];
            }
        }
    }

    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.distanceFilter=50.0f;
    [self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    newLocation = locations.lastObject;
    coordinate = [newLocation coordinate];
    NSLog(@"%f %f",coordinate.latitude,coordinate.longitude);
    MKCoordinateRegion  r= MKCoordinateRegionMakeWithDistance(coordinate, 400, 400);
    self.mapView.region=r;
    [self.mapView setCenterCoordinate:coordinate];
    Annotation *annot=[[Annotation alloc]initWithTitle:@"My Location" AndCoordinate:coordinate];
    [self.mapView addAnnotation:annot];
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate radius:1000];
    circle.title = @"";
    [self.mapView addOverlay:circle];
}

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[MKCircle class]])
    {

        MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithCircle:overlay];
        circleView.strokeColor=[UIColor blackColor];
     circleView.lineWidth=1.2;
       circleView.alpha=1;
        return circleView;
    }
    return nil;
}

1 个答案:

答案 0 :(得分:0)

您可以实施Apple Bread crumb类来实现路线绘制。

请检查此链接:https://developer.apple.com/library/archive/samplecode/Breadcrumb/Introduction/Intro.html

相关问题