How to get E6 format of Longitude Latitude for Google Maps on Android

末鹿安然 提交于 2019-11-30 03:38:56
Rakib

So it's a two step process - thanks to hooked82's answer


step 1. Conversion from DMS to Decimal Degrees From Wikipedia

Given a DMS (Degrees, Minutes, Seconds) coordinate such as 87°43′41″ W, it's trivial to convert it to a number of decimal degrees using the following methods:

  • Total number of degrees
    = 87
  • Total number of seconds
    = 43′41″ = (43*60 + 41*1) = 2621 seconds.
  • The fractional part is total number of seconds divided by 3600
    = 2621 / 3600 = 0.728056
  • Add fractional degrees to the whole degrees to produce the final result
    = 87 + 0.728056 = 87.728056.
  • Since it is a West longitude coordinate, negate the result.
    = -87.728056.
  • Long-Lat reference:

    Lat.  North = +
    Lat.  South = -
    Long. East  = +
    Long. West  = -
    

    step 2. Conversion from Decimal Degrees to MicroDegrees (the E6 format) From SO discussion

    MicroDegrees (the E6 format) = DecimalDegrees * 1e6
    --- as mentioned in AndroidDevGuide as well

    thus,

    float lat   = -23.4456f;   //in DecimalDegrees
    float lng   = 45.44334f;   //in DecimalDegrees
    GeoPoint gp = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
    
    hooked82

    I'm not sure of a programmatic approach to converting a DMS Coordinate to Microdegrees, but there is a manual conversion process which I came across at:

    http://en.wikipedia.org/wiki/Geographic_coordinate_conversion#Conversion_from_DMS_to_Decimal_Degree

    Also, take a look at this SO question:

    Android GeoPoint with lat/long values

    If you're manually trying to get GPS coordinates and want values that Android can handle, you can always go to Google Maps and Right-Click on a point on the map and select "What's Here". It will give you the lat/long of that position, though there are many ways of getting these.

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!