从静态谷歌地图获取经度和纬度 [英] Get latitude and longitude from static google map

查看:111
本文介绍了从静态谷歌地图获取经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示静态地图,并在鼠标上显示在地图上获取鼠标上的纬度和经度

解决方案

需要进行一些计算,您可以找到所需的方法本演示的源代码: https://developers.google.com/maps/ documentation / javascript / examples / map-coordinates?csw = 1



函数实现了这些计算以用于静态映射:

 函数FX(lat,//静态地图的中心纬度
ng,//静态地图的中心经度
zoom,//缩放静态地图
width,//静态地图的宽度
height,//静态地图的高度
mouseX,// x元素
中的mouseevent的坐标mouseY //元素内的mouseevent的y坐标
){


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;


演示: http://jsfiddle.net/doktormolle/yxf2C/show/

I want to display a static map and on mouse over the map get latitude and longitude on mouse over the map

解决方案

It needs some calculations, you'll find the required methods in the source of this demo: https://developers.google.com/maps/documentation/javascript/examples/map-coordinates?csw=1

function that implements these calculations for usage with a static map:

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;

    }

Demo: http://jsfiddle.net/doktormolle/yxf2C/show/

这篇关于从静态谷歌地图获取经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆