简体   繁体   中英

iOS Action, based on region in MapKit

Basically what I'm trying to accomplish is a GPS tour guide app, where when you enter a certain region and a sound file is played.
Let's say i've got 10 sound files and 10 regions.
Is there a way to basically define a line on the map, and if the user crosses the line - the app changes the sound file being played?

Thanks

MKMapViewDelegate has a function mapView:regionDidChangeAnimated: which occurs when user scrolls the map. In this function you can switch music or whatever you need based on current map position (for example by checking which region is closer to the map center etc.):

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    /* do what you need with mapView.region */
}

Maybe - (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy on CLLocationManager is what you are looking for. You can define multiple regions -- as soon as the user enters one of the defined regions you will start to receive notifications. More info here

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