Issue
I have stored the latitude and longitude inside my database as a string, e.g 23.563987,120.761719
How can i trim them into two seperate integers so that it can fit into my code? thanks!
[and sorry that i'm new to java....]
My map code is as below:
GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getApplicationContext());
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.addMarker(new MarkerOptions().position(
new LatLng(23.563987,120.761719)).title("Marker"));
mMap.setMyLocationEnabled(true);
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(
23.563987,120.761719));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
Solution
You can split the strung and convert it back to doubles.
String locationString = *from DB*
String[] latLongStrings = locationString.split(",");
double lat = Double.parseDouble(latLongStrings[0]);
double long = Double.parseDouble(latLongStrings[1]);
However, you might want to adjust your DB schema to have two REAL columns instead of one TEXT
Answered By - alex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.