2

In my Android application I need to load Google map and show the location according to the Latitude and the Longitude values provided. I referred the following tutorial and its completely ok. Work fine.

Link to the tutorial I followed

Problem is Latitude and Longitude values are stored in SQLite database in the DMS Fromat. If those values were in the Decimal Degrees format then No problem, as I can do the way it was in that tutorial.

I need to Show the exact place by adding Overlay Item(I have given the Longitude and Latitude values by DMS Format).

[Example values: 36°7'59''N, 5°25'59''W]

Thanks...

JibW
  • 4,538
  • 17
  • 66
  • 101
  • check this link for your answer http://stackoverflow.com/questions/11389397/getting-current-location-longitude-and-latitude-in-android – Arun May 17 '13 at 09:22

2 Answers2

0

If u want to convert latitude longitude value to degree minutes format then code is here...

String locLat, locLng;

locLat = Double.toString(location.getLatitude());
locLng = Double.toString(location.getLongitude());

String locLatTodeg = DoubleToDeg(locLat);
String locLngTodeg = DoubleToDeg(locLng);

private String DoubleToDeg(String locLng) {
    // TODO Auto-generated method stub
    String retStringLoc = null;
    try {
        String firString = locLng.replace(".", ";");
        String[] firLocArr = firString.split(";");
        Float deg = new Float("." + firLocArr[1]);
        Float Cnvtddeg = deg * 60;
        String secString = new Float(Cnvtddeg).toString().replace(".", ";");
        String[] secLocArr = secString.split(";");
        Float min = new Float("." + secLocArr[1]);
        Float Cnvtdmin = min * 60;
        String tirString = new Float(Cnvtdmin).toString().replace(".", ";");
        String[] tirLocArr = tirString.split(";");
        retStringLoc = firLocArr[0] + "°" + secLocArr[0] + "'"
                + tirLocArr[0] + "''";
    } catch (Exception e) {
        // Log.i("Exception", e.toString());

    }
    return retStringLoc;
}

I think this is helpful for u....

Laksh
  • 6,717
  • 6
  • 33
  • 34
user4232
  • 592
  • 1
  • 12
  • 37
  • When I pass this string for this method it gives an exception. String str = "32°18'23.1''N, 122°36'52.5''W"; The exception message is [For input string: ".1'' N, 122° 36' 52"] – JibW Aug 04 '11 at 12:33
0

I'm sorry for misunderstanded the question. `doit("36°7'59''N");

public void doit(String lat) {

        String str = lat;
        String [] temp = null;
        String dtemp = null;
        String [] pass = new String[4];
        //temp = str.split("[\"]|\"[\']");
        temp = str.split("[\"]|[\']" ); 
        System.out.println("temptemptemptemp  "+temp);
        dtemp = str.replace("\"", "°");
        System.out.println("dtempdtempdtemp  "+dtemp);
        System.out.println("Formated DCM---------- : "+dtemp);

        String [] temp1 = temp[0].split("°");
        System.out.println("\ndegree temp: "+temp1[0]);
        System.out.println("\nminutes temp: "+temp1[1]);
        pass[0] =  temp1[0];
        pass[1] =  temp1[1];
        pass[2] =  temp[1];

        dump(pass);


    }

 public void dump(String []s) {
        for (int i = 0 ; i < s.length ; i++) {
            System.out.println("\ndegree : "+s[0]);
            System.out.println("\nminutes : "+s[1]);
            System.out.println("\nsecond : "+s[2]);

            String deg = s[0] ;
            int ndeg = Integer.parseInt(deg);
            String min = s[1] ;
            double nmin = Double.parseDouble(min);
            String sec = s[2] ;
            double nsec = Double.parseDouble(sec);
            double decimaldms = (ndeg+(nmin/60)+(nsec/3600));
            System.out.println("\nfinaldecimal : "+decimaldms);
        }
    }

 `

I think this is help for u.

user4232
  • 592
  • 1
  • 12
  • 37