Convert lat/lon to pixels and back

后端 未结 2 1950
说谎
说谎 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)];
    

提交回复
热议问题