简体   繁体   中英

iOS CoreLocation plot user location on top of image

i'm trying to create a building navigation application similar to http://navigationapps.com/wp-content/uploads/2010/10/point-inside-2.png . I'm planning on displaying the building floor plan image as a UIImageView and using CoreLocation to get the longitude and latitude coordinates for the pin pointer. The next step - which im also stuck on, how do i plot the point on the image? - i am already able to retrieve the users lat and lot coordinates..

Well, you firstly a UIImageView to display some sort of icon for the pin pointer, and then a function to transform lat/long coordinates into the position on your image.

Assuming your building floor plan image is aligned with north at the top,

- (CGPoint)plotPointOfLocation:(CLLocationCoordinate2D)location {
    CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(/* the lat/long of the top-left of the plan image */);
    CLLocationCoordinate2D bottomRightCoordinate = CLLocationCoordinate2DMake(/* the lat/long of the bottom-right of the plan image */);
    CGSize planImageSize = CGSizeMake(/* the size of the plan image, as drawn on the screen, in pixels */);

    CLLocationDegrees latSpan = bottomRightCoordinate.latitude - topLeftCoordinate.latitude;
    CLLocationDegrees longSpan = bottomRightCoordinate.longitude - topLeftCoordinate.longitude;

    CLLocationCoordinate2D offsetLocation = CLLocationCoordinate2DMake(location.latitude - topLeftCoordinate.latitude,
                                                                       location.longitude - topLeftCoordinate.longitude);

    CGPoint ret = CGPointMake((offsetLocation.latitude / latSpan) * planImageSize.width,
                              (offsetLocation.longitude / longSpan) * planImageSize.height);
    return ret;
}

Then just set your pin UIImageView 'center' property to the value returned from this method.

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