When you are making an app with GPS routes and you want to create test data (for unit tests or just testing without moving around), you can use the following code;
In ViewDidLoad or whatever used to initialise the view, put:
- var tapRecogniser = new UITapGestureRecognizer(this, new MonoTouch.ObjCRuntime.Selector(“MapTapSelector:“));
- map.AddGestureRecognizer (tapRecogniser);
And somewhere in the same class;
- [Export(“MapTapSelector:“)]
- protected void OnMapTapped(UIGestureRecognizer sender)
- {
- CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map);
- locations.Add (tappedLocationCoord);
- HandleDidUpdateUserLocation (this,
- new CLLocationsUpdatedEventArgs(
- new CLLocation []{
- new CLLocation(tappedLocationCoord.Latitude, tappedLocationCoord.Longitude)
- }
- )
- );
- }
In my case
- List<CLLocationCoordinate2D> locations
which contains all the already clicked locations so we can draw a nice path from all taps which is the same as say a run or a walk or a drive. Add some small debugging fields for speed and altitude and you can test most real life situations.
Be the first to leave a comment. Don’t be shy.