简体   繁体   中英

Placing blue dot in mapKit with a desired location

For demonstration purpose, i need to simulate the user location in a Mapkit view. It seems that it is possible with an undocumented API to place the blue dot anywhere on the map view. Unfortunately, i don't know witch undocumented API to use ? Any help ?

Did you set this?

mapView.showsUserLocation = YES;

Setting a specific location is a bit more difficult, but certainly do-able without undocumented APIs. See code below:

- (void)animateToSelectedPlace:(CGFloat)zoomLevel {
    MKCoordinateRegion region;
    region.center = [self getCoordinateFromComponents:chosenLatitude:chosenLongitude];

    MKCoordinateSpan span = {zoomLevel,zoomLevel};
    region.span = span;

    [mapView setRegion:region animated:YES];
}

-(CLLocationCoordinate2D)getCoordinateFromComponents:(NSNumber*)latitude:(NSNumber*)longitude {
    CLLocationCoordinate2D coord;
    coord.latitude = latitude.doubleValue;
    coord.longitude = longitude.doubleValue;
    return coord;
}

Not sure that it is possible to set CUSTOM user location (usually people use image simulating blue user point). Though i am not 100% sure, so you have a chance to try something like this to check if it is possible to deal with userLocation as with MKAnnotation ...

CLLocationCoordinate2D c = self.mapView.userLocation.location.coordinate;
[[self.mapView userLocation] setCoordinate:c];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM