它需要一些计算,您将在此演示的源代码中找到所需的方法:https://developers.google.com/maps/documentation/javascript/examples/map-coordinates ?csw = 1
实现这些计算以使用静态映射的函数:
function FX(lat,//center-latitude of the static-map
lng,//center-longitude of the static-map
zoom,//zoom of the static-map
width,//width of the static-map
height,//height of the static-map
mouseX,//x-coordinate of the mouseevent inside the element
mouseY//y-coordinate of the mouseevent inside the element
){
var x = mouseX-(width/2),
y = mouseY-(height/2),
s = Math.min(Math.max(Math.sin(lat * (Math.PI / 180)), -.9999), .9999),
tiles = 1 << zoom,
centerPoint={
x: 128 + lng * (256/ 360),
y: 128 + 0.5 * Math.log((1 + s) / (1 - s))
*-(256 / (2 * Math.PI))
},
mousePoint={
x:(centerPoint.x*tiles)+x,
y:(centerPoint.y*tiles)+y
},
mouseLatLng={
lat:(2 * Math.atan(Math.exp(((mousePoint.y/tiles) - 128)
/ -(256/ (2 * Math.PI)))) -
Math.PI / 2)/ (Math.PI / 180),
lng:(((mousePoint.x/tiles) - 128) / (256 / 360))
};
return mouseLatLng;
}
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/doktormolle/yxf2C/show/
| 归档时间: |
|
| 查看次数: |
2096 次 |
| 最近记录: |