0

I have a little problem with a calculation.

What I want is for the user of the app to position a moving mapannotation somewhere in the visible area of the map. And while the annotations location is changing (gps unit) the map should move but the pin always stay at that point in screen.

I am trying to use the results from this stackoverflow answer

and result from

-(CLLocationDistance) calcluateDistance:(CLLocationCoordinate2D)annotationLocation{

CLLocation *annotationPosition = [[[CLLocation alloc]initWithLatitude:annotationLocation.latitude longitude:annotationLocation.longitude]autorelease];
CLLocation *centrePosition = [[CLLocation alloc]initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude];
CLLocationDistance distance = [centrePosition distanceFromLocation:trackerPosition];
return distance;

}

and throw results into this stackoverflow anser

Something is not really working. I know my explanation is not superclear so please ask me if anything is unclear :)

May thanks

Community
  • 1
  • 1
Pedroinpeace
  • 1,419
  • 1
  • 14
  • 20

1 Answers1

0

One problem with the approach you are using is that distance does not tell you direction, i.e. 40 meters away but its it 40 meters was or west?

One function that could be usefull to you is [mapView convertPoint:annotationPoint toCoordinateFromView:mapView]

If you figure our the point relative to the map view where the annotation should stay, store this value, and use [mapView convertPoint:annotationPoint toCoordinateFromView:mapView] to figure out the coordinate in the map view.

Hope it helps.

JoelEsli
  • 451
  • 3
  • 8