2015-12-16 38 views
0

如何使用IOS中的mapkit在Map上显示用户。此代码仅在地图上显示印度,而不是定义的坐标。如何使用IOS中的mapkit在地图上显示用户

mapView.delegate = self; 
    mapView.showsUserLocation = YES; 
    objLocationManager = [[CLLocationManager alloc] init]; 
    objLocationManager.distanceFilter = kCLDistanceFilterNone; 
    objLocationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
    objLocationManager.delegate = self; 
    #ifdef __IPHONE_8_0 
    if(IS_OS_8_OR_LATER) { 
     // Use one or the other, not both. Depending on what you put in info.plist 
     //[objLocationManager requestWhenInUseAuthorization]; 
     [objLocationManager requestAlwaysAuthorization]; 
    } 
    #endif 
    [objLocationManager startUpdatingLocation]; 

    mapView.showsUserLocation = YES; 
    [mapView setMapType:MKMapTypeStandard]; 
    [mapView setZoomEnabled:YES]; 
    [mapView setScrollEnabled:YES]; 
    mapView.delegate=self; 

回答

1

您正在开始位置更新,您将通过它获取当前位置,但MKMapview如何知道位置更改? 对于MKMap视图来采用位置更改,您必须将委托设置为MKMapview,并且您已完成该部分,但您忘记了委托方法。

- (void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation *)aUserLocation {} 

此委托方法会将您当前的位置发送给您所需的mapview。 如果您想使用默认的Delegate方法,那么您必须将标记放置在地图上,并使用从CLLocation更新方法接收到的当前坐标。

如果你要使用默认的委托方法,那么不要忘记确认MKMapViewDelegate。

让我们知道,如果作品,我相信它会...有一个好的一天

+0

是的,我已经使用这个委托,并提到的代码的MKCoordinateRegion区= MKCoordinateRegionMakeWithDistance(userLocation.coordinate,800,800 ); [self.mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES]; [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];这也不起作用。 –

+0

打印在我的程序中的日志正试图启动MapKit位置更新,而不提示进行位置授权。必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]。 –

+0

添加几行后,显示放大的位置,但不显示地图上的注释。 MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation,0.5 * METERS_PER_MILE,0.5 * METERS_PER_MILE); [self.mapView setRegion:viewRegion animated:YES]; –

相关问题