Convert lat/lon to pixels and back

后端 未结 2 1948
说谎
说谎 2021-02-13 04:14

I\'m using google maps in my application, and I have a webserver with a databse filled with lat/lon values. I want to mark them on the map, but I also want to cluster them toget

相关标签:
2条回答
  • 2021-02-13 04:25

    Using Google Maps API v3:

    var latLng = // your position object here
    var projection = map.getProjection();
    var bounds = map.getBounds();
    var topRight = projection.fromLatLngToPoint(bounds.getNorthEast());
    var bottomLeft = projection.fromLatLngToPoint(bounds.getSouthWest());
    var scale = Math.pow(2, map.getZoom());
    var worldPoint = projection.fromLatLngToPoint(latLng);
    return [Math.floor((worldPoint.x - bottomLeft.x) * scale), Math.floor((worldPoint.y - topRight.y) * scale)];
    
    0 讨论(0)
  • 2021-02-13 04:39

    There is a JavaScript example to do this on this page as part of the documentation for the Google Maps API. Bear in mind you need to look at the page source to see it. It's not an actual documentation page but rather an example.

    0 讨论(0)
提交回复
热议问题