Nimisha Patel
Nimisha Patel

Reputation: 406

Convert GMSMapView coordinate to iPhone screen point(x,y)

I have tried to covert the marker position latitude-longitude to iPhone screen x and y coordinate, but it gives me negative value sometimes.

MapView is added in main view from storyboard. self.mapView.frame - It is equal to main view frame iPhone 8 plus simulator = (origin = (x = 0, y = 0), size = (width = 414, height = 736))

Marker position : (latitude = 22.811061859130859, longitude = 70.862533569335938)

CGPoint pointInScreen = [self.mapView.projection pointForCoordinate:marker.position];

Returns value - (x = -38547.58203125, y = 7061.60107421875) Which is not screen point. My marker is visible on the screen.

Can anyone suggest me the right way to find out the screen x,y coordinate based on the marker latitude-longitude position?

Upvotes: 0

Views: 1085

Answers (2)

TheTiger
TheTiger

Reputation: 13354

There are few things to check:

  1. marker should be visible on map.
  2. Cross check your coordinates.
  3. [self.mapView.projection pointForCoordinate:marker.position] function will work after loading the map properly.

Upvotes: 1

dahiya_boy
dahiya_boy

Reputation: 9503

You have to do like this

Upvotes: 0

Related Questions