0

Is there a way to set the mapView.userLocation.location.coordinate by code?

I know there is CLLocationCoordinate2D for set coordinates but then it isn't the userLocationCoordinate.

I have tried to assign a number to mapView.userLocation.coordinate.latitude, but then I get "this expression is not assignable"

mapView.userLocation.coordinate.latitude = 0;

So is there a way to set UserLocation (except from setting a default location in the simulator)?

Dennis
  • 2,119
  • 20
  • 29
NickVH
  • 143
  • 1
  • 11

2 Answers2

0

It may not possible to set MKUserLocation coz in its definition it suggest that it is readonly Property.

 // The annotation representing the user's location
 @property (nonatomic, readonly) MKUserLocation *userLocation;

Instead of this, you can add MKAnnotationView in

 -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation

where you want to highlight, as User location like,

May It help you.

HTH, Enjoy Coding !!

Viral Savaj
  • 3,379
  • 1
  • 26
  • 39
0

you can not set user's current location through code as it's read-only property.

You can use CLLocationManager if you want user's current location. please refer below link for that Link 1 Link 2

Or you can use gpx file to set your device's current location whatever you want. To do that please refer this link

Hope this will help you.

Community
  • 1
  • 1
Malav Soni
  • 2,739
  • 1
  • 23
  • 52