Android Show Map location when Longitude/ Latitude values are in DMS Format
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'5开发者_如何转开发9''W]
Thanks...
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.
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....
精彩评论