What is the best way to calculate the pixel distance between to coordinates (lat/lon) in a Google Map. I am not asking about the distance in km/miles (therefore I have a library), but pixels on the screen considering the current zoom factor.
Background: I want to draw overlays without overlapping them. So I need to calculate the offset for these positions. So in a lower zoom factor a distance of 500 km can mean the overlays do overlap, while at 50km they don't.
Of course, any other algorithm to avoid overlaps not based on the pixel distance would be appreciated.
-- Update --
Guess is is going in the direction of clustering, will check this:
-- Update --
Most likely I can use this here: http://code.google.com/apis/maps/documentation/javascript/reference.html
google.maps.MapCanvasProjection.fromLatLngToDivPixel
To get the projection I will use the answers here:
The API returns information based on the recommended route between start and end points. You can request distance data for different travel modes, request distance data in different units such kilometers or miles, and estimate travel time in traffic.
As far as I know there is no limit on how many markers you can add to a google-maps based map - however the performance of your map will decrease when you add a lot of them.
You can limit the view able area and zoom level of the google map using limit panning settings. Google map plugin provides easiest way to limit panning/dragging so the map stays within certain bounds using limit panning settings. Step 1 Go to Add or Edit Map and scroll down to 'Limit Panning Settings' section.
First I found that what I am looking for is subject of the clustering libraries / examples:
The examples showed me a method google.maps.MapCanvasProjection.fromLatLngToDivPixel
, which required a projection of the map. Eventually the following topics revealed how to get this projection:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With