简体   繁体   English

在Google Maps API V3中获取imageMapType的X,Y坐标

[英]Getting X, Y coordinates of an imageMapType in Google Maps API V3

I'm using ImageMapType to render a custom image over the google maps (API V3). 我正在使用ImageMapType在Google地图(API V3)上呈现自定义图像。 I would like to get the X, Y of a certain Lat/Lng on the map. 我想在地图上获得某个纬度/经度的X,Y。 This works fine for the center of the map (which is at Lat 0 and Lng 0) but does not work for the other parts of the map because the X,Y values are calculated according to the entire world map and not that section of the world that my custom map is overlayed onto. 这适用于地图中心(位于Lat 0和Lng 0),但不适用于地图的其他部分,因为X,Y值是根据整个世界地图计算的,而不是根据地图的该部分计算的我的自定义地图所覆盖的世界。 在此处输入图片说明

How could I get the proper X, Y values on the picture ? 如何获得图片上正确的X,Y值?

The algorithm I'm using for finding the X and Y is the one below: 我用于查找X和Y的算法如下:

    double latitude    = location.getLatitude();
    double longitude   = location.getLongitude();

    int mapWidth    = 800;
    int mapHeight   = 450;

    // get x value
    double x = (mapWidth*(180+longitude)/360) % mapWidth+(mapWidth/2);

    // convert from degrees to radians
    double latRad = latitude * java.lang.Math.PI / 180;

    // get y value
    double mercN = java.lang.Math.log(java.lang.Math.tan((java.lang.Math.PI / 4)+( latRad / 2)));
    double y     = (mapHeight / 2)-( mapWidth * mercN/(2 * java.lang.Math.PI));


    System.out.println("X : " + (x - (mapWidth / 2)) + " Y: " + y);

I'm not sure, this will solve your prolem, but may be could help you a bit: 我不确定,这是否可以解决您的问题,但可能会有所帮助:

https://developers.google.com/maps/documentation/javascript/reference?hl=fr#Projection https://developers.google.com/maps/documentation/javascript/reference?hl=fr#Projection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM