Google静态地图用手指移动地图 [英] Google Static Maps Move maps with a finger
问题描述
我使用 Static Maps V2 API 下载地图,然后显示地图在我的移动设备上,现在我想用我的手指和我的设备上的触摸屏移动地图。
如何计算移动地图的新中心,了解以前的地图中心,缩放级别和地图移动了多少像素?
下面的代码应该可以做到这一点。
调用*** ByPixels(),delta是以像素为单位的偏移量。
$ p $ static final double GOOGLEOFFSET = 268435456;
static final double GOOGLEOFFSET_RADIUS = GOOGLEOFFSET / Math.PI;
static final double MATHPI_180 = Math.PI / 180;
static private final double preLonToX1 = GOOGLEOFFSET_RADIUS *(Math.PI / 180);
public final static double LonToX(double lon){
return Math.round(GOOGLEOFFSET + preLonToX1 * lon);
}
public final static double LatToY(double lat){
return Math.round(GOOGLEOFFSET - GOOGLEOFFSET_RADIUS * Math.log((1 + Math.sin(lat * MATHPI_180 ))/(1-Math.sin(lat * MATHPI_180)))/ 2);
}
public final double XToLon(double x){
return((Math.round(x) - GOOGLEOFFSET)/ GOOGLEOFFSET_RADIUS)* 180 / Math.PI;
public final double double YToLat(double y){
return(Math.PI / 2 - 2 * Math.atan(Math.exp((Math.round y) - GOOGLEOFFSET)/ GOOGLEOFFSET_RADIUS)))* 180 / Math.PI;
}
public final static double adjustLonByPixels(double lon,int delta,int zoom){
return XToLon(LonToX(lon)+(delta <<(21 - 放大)));
}
public final double double adjustLatByPixels(double lat,int delta,int zoom){
return YToLat(LatToY(lat)+(delta <<(21 - 放大)));
}
I’m downloading maps using Static Maps V2 API then display map on my mobile device, now I would like to move map using my finger and a touch screen on my device.
How can I calculate a new center for moved map, knowing previous map center, zoom level and how many pixels map has been moved?
The following code should do the trick; Call adjust***ByPixels(), with delta being the offset in pixels.
static final double GOOGLEOFFSET = 268435456;
static final double GOOGLEOFFSET_RADIUS = GOOGLEOFFSET / Math.PI;
static final double MATHPI_180 = Math.PI/180;
static private final double preLonToX1 = GOOGLEOFFSET_RADIUS * (Math.PI/180);
public final static double LonToX( double lon ) {
return Math.round(GOOGLEOFFSET + preLonToX1 * lon);
}
public final static double LatToY( double lat ) {
return Math.round( GOOGLEOFFSET - GOOGLEOFFSET_RADIUS * Math.log((1 + Math.sin(lat * MATHPI_180)) / (1 - Math.sin(lat * MATHPI_180))) / 2);
}
public final static double XToLon( double x) {
return ((Math.round(x) - GOOGLEOFFSET) / GOOGLEOFFSET_RADIUS) * 180/ Math.PI;
}
public final static double YToLat( double y) {
return (Math.PI / 2 - 2 * Math.atan(Math.exp((Math.round(y) - GOOGLEOFFSET) / GOOGLEOFFSET_RADIUS))) * 180 / Math.PI;
}
public final static double adjustLonByPixels( double lon, int delta, int zoom) {
return XToLon(LonToX(lon) + (delta << (21 - zoom)));
}
public final static double adjustLatByPixels( double lat, int delta, int zoom) {
return YToLat(LatToY(lat) + (delta << (21 - zoom)));
}
这篇关于Google静态地图用手指移动地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!