Question

I need to simulate how my application will look when a user is driving around for a demo. I have a MKMapView, how can I simulate the look of a user driving around which will use the map.userLocation functionality, which obviously will not be available in the demo.

Thanks!

Was it helpful?

Solution 2

Well I got something going, I just did essentially this

- (void)moveIcon:(MKAnnotationView*)locationView toLocation:(CLLocation*)newLoc
{
    LocationAnnotation* annotation = [[[LocationAnnotation alloc] initWithCoordinate:newLoc.coordinate] autorelease];
    [locationView setAnnotation:annotation];
    [map setCenterCoordinate:newLoc.coordinate animated:YES];
}

Then I call this guy in a loop between all of my vertices with a slight delay. Works quite qell.

OTHER TIPS

No way to simulate in iPhone simulator. You'll need to load it onto your device and move around.

I'm not an iPhone dev expert, but how does the map view receive the coordinates? If it's through a function that calls the CoreLocation API, could you possibly just write a function that randomly generates longitude and latitude values at a certain time interval and have your map view pull the coordinates from there instead? Just a thought.

You could also check out iSimulate which claims to be able to simulate several features only available on the iPhone in the iPhone simulator include CoreLocation. I have not tried this myself so your mileage may vary.

In order to simulate driving you'll need to establish 2 basic functionalities:

  1. Reading CLLocations from an archive (which you'd log during the drive test with a device). Ideally you'll do this based on the timestamps on the locations, i.e. reproducing the exact same location updates which were received during the drive test.

  2. Updating your MKAnnotationView's position on the map based on the locations read from log.

For part 1, take a look at CLLocationDispatch, a handy class which provides archiving/unarchiving of CLLocations and dispatches them to one or more listeners (using CLLocationManagerDelegate protocol).

For part 2, take a look at Moving-MKAnnotationView.

I found a better way would be to subclass MKUserLocation:

class SimulatedUserLocation: MKUserLocation {
    private var simulatedCoordinate = CLLocationCoordinate2D(latitude: 39, longitude: -76)
    override dynamic var coordinate: CLLocationCoordinate2D {
        get {
            return simulatedCoordinate
        }
        set {
            simulatedCoordinate = newValue
        }
    }
}

Then add it as an annotation mapView.addAnnotation(SimulatedUserLocation()). (You might also want to hide the real location first mapView.showsUserLocation = false)

iOS would render the annotation exactly like the real user location.

dynamic is used on the property so that changing coordinate triggers KVO and moves it on the map.

The answer is NO. Then, how about adding an abstraction layer between your code and MKMapKit? You can do xUnit tests for your objective.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top