amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 346 forks source link

Translate map location to screen pixel location, vice versa #645

Open ritolika opened 5 years ago

ritolika commented 5 years ago

SUMMARY

A function which allows the translation between a point on the map to a point on the screen. And the other way around.

DETAILS

For example it could look something like this:

var map = new Map();
...
var position /*Lat Lng*/ = new Position(37.797496, -122.402054); 

//method to check if lat lng is visible on screen right now
bool isVisibleOnScreen = map.IsVisibleOnScreen(position);

if(isVisisbleOnScreen)
var screenPosition /*X and Y*/ = map.TranslateLatLngToPixelCoordinates(position); //returns null if position is not visible on screen
//and other way around: 

Position mapPos = map.TranslatePixelCoordinatesToLatLng(x, y);

PLATFORMS

ritolika commented 5 years ago

I've found that in Xamarin.Forms.Maps there is this function in MapRenderer: projection.FromScreenLocation(new global::Android.Graphics.Point(0, 0)); Maybe it could be useful?