Java code for WGS84 to Google map position and back

前端 未结 6 827
陌清茗
陌清茗 2020-12-31 12:16

Searching for some sample code for converting a point in WGS84 coordinate system to a map position in Google Maps (pixel position), also supporting zoom levels.

If

6条回答
  •  再見小時候
    2020-12-31 13:14

    I ported this to PHP - here's the code, if anyone would need it:

    To mercator:

    $lon = ($lon * 20037508.34) / 180;
    $lat = log(tan((90 + $lat) * M_PI / 360)) / (M_PI / 180);
    $lat = $lat * 20037508.34 / 180;
    

    From mercator:

    $lon = ($lon / 20037508.34) * 180;
    $lat = ($lat / 20037508.34) * 180;
    $lat = 180/M_PI * (2 * atan(exp($lat * M_PI / 180)) - M_PI / 2);
    

提交回复
热议问题