Android - Cursor onMapReady (Markers) - android

I'm trying to "inflate" my content from SQLite into Markers but the solution I took of here it's not working, and it's not throwing any information on Log.
I'm a bit new on this Marker stuff and SQLite
My code inside the Fragment:
SQLiteHelper dbHelper = new SQLiteHelper(getActivity());
pds = new ParksDataSource(dbHelper.db);
parks = pds.getAllParks();
List<Marker> markersList = new ArrayList<Marker>();
int i = 0;
Cursor cursor = db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS,
null);
try {
while (cursor.moveToNext()) {
String[] latlong = cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_COORDINATES)).split(",");
double latitude = Double.parseDouble(latlong[0]);
double longitude = Double.parseDouble(latlong[1]);
mark = new LatLng(latitude, longitude);
Marker mPark = mMap.addMarker(new MarkerOptions().position(mark)
.title(cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)))
.icon(BitmapDescriptorFactory.fromBitmap(writeTextOnDrawable(R.mipmap.ic_pin, cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_FREE))))));
mPark.setTag(0);
markersList.add(mPark);
Log.d("HierParks", "Pin: " + i + ", " + latitude + "," + longitude + " - Park:" + cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)));
i++;
}
} finally {
cursor.close();
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}`
Thank you for your time.

Finally I managed to fix it, hope this help someone.
My ParkDataSource:
public Cursor getAll() {
return db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS,
null);
}
My Fragment:
SQLiteHelper dbHelper = new SQLiteHelper(getActivity());
pds = new ParksDataSource(dbHelper.db);
cursor = pds.getAll();
List<Marker> markersList = new ArrayList<Marker>();
int i = 0;
try {
while (cursor.moveToNext()) {
String[] latlong = cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_COORDINATES)).split(",");
double latitude = Double.parseDouble(latlong[0]);
double longitude = Double.parseDouble(latlong[1]);
mark = new LatLng(latitude, longitude);
if (cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_SLOTS)) == null){
Marker mPark = map.addMarker(new MarkerOptions().position(mark)
.title(cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)))
.icon(BitmapDescriptorFactory.fromBitmap(writeTextOnDrawable(R.mipmap.ic_pin, cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_FREE))))));
mPark.setTag(0);
markersList.add(mPark);
}
i++;
}
} finally {
cursor.close();
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}

Related

googlemap shows two markers rather than one

on mapReady, i want only one marker with its address. but it shows two markers.
i do not understand why. i have all address list that i will display on the marker for each locations and positions. the final code is:
list_layout_list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
HistoryItem item = (HistoryItem) list_layout_list.getItemAtPosition(position);
String hintString = item.getHint(getHistoryResult.item_class);
int device_id = (int) id;
//on selectionne les ligne histo par position sur les items (balises).
List<Address> addresses;
try{
addresses = new Geocoder(HistoryActivity.this).getFromLocation(Double.parseDouble(item.items.get(0).lat), Double.parseDouble(item.items.get(0).lng), 1);
if ("start".equals(hintString)) {
MarkerOptions mo = new MarkerOptions();
mo.position(new LatLng(Double.parseDouble(item.items.get(0).lat), Double.parseDouble(item.items.get(0).lng)));
mo.title(addresses.get(0).getAddressLine(0));
Marker m = map.addMarker(mo);
assert m != null;
m.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(mo.getPosition(), 14));
}if ("stop".equals(hintString)) {
MarkerOptions mo = new MarkerOptions();
mo.position(new LatLng(Double.parseDouble(item.items.get(0).lat), Double.parseDouble(item.items.get(0).lng)));
mo.title(addresses.get(0).getAddressLine(0));
Marker m = map.addMarker(mo);
assert m != null;
m.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(mo.getPosition(), 14));
} else if ("end".equals(hintString)) {
MarkerOptions mo = new MarkerOptions();
mo.position(new LatLng(Double.parseDouble(item.items.get(0).lat), Double.parseDouble(item.items.get(0).lng)));
mo.title(addresses.get(0).getAddressLine(0));
Marker m = map.addMarker(mo);
assert m != null;
m.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(mo.getPosition(), 14));
} else if ("event".equals(hintString)) {
Event event = new Event();
LatLng geopoint = new LatLng((double) event.latitude, (double) event.longitude);
MarkerOptions mo = new MarkerOptions();
mo.position(geopoint);
mo.title(event.device_name);
Marker m = map.addMarker(mo);
assert m != null;
m.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(mo.getPosition(), 14)));
} else if ("drive".equals(hintString)) {
map.clear();/* ceci pour initialiser la carte pour des parcours differents*/
for(int i=0; i< position; i++) {
// initialisation du temps mis
ArrayList<HistoryItemCoord> historyItemCoords = new ArrayList<>(item.items);
final List<GeoPoint> points = new ArrayList<>();
long previousCoordTime = historyItemCoords.get(0).getTimestamp();
int loopId = 0;
for (HistoryItemCoord coord : historyItemCoords)
{
if (loopId == 0 || (loopId > 0 && previousCoordTime != coord.getTimestamp()))
{
GeoPoint point = new GeoPoint(Double.parseDouble(coord.lat), Double.parseDouble(coord.lng));
points.add(point);
}
previousCoordTime = coord.getTimestamp();
loopId++;
}
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.color(Color.parseColor("#d61327"));
polylineOptions.width(Utils.dpToPx(HistoryActivity.this, 3));
for (GeoPoint point : points)
{
polylineOptions.add(new LatLng(point.getLatitude(), point.getLongitude()));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(point.getLatitude(), point.getLongitude()),14));
}
map.addPolyline(polylineOptions);
}
}
} catch (IOException e)
{
e.printStackTrace();
}
}
});
In this part of code for example:
addresses = new Geocoder(HistoryActivity.this).getFromLocation(Double.parseDouble(item.items.get(0).lat), Double.parseDouble(item.items.get(0).lng), 1);
if ("start".equals(hintString)) {
MarkerOptions mo = new MarkerOptions();
mo.position(new LatLng(Double.parseDouble(item.items.get(0).lat), Double.parseDouble(item.items.get(0).lng)));
mo.title(addresses.get(0).getAddressLine(0));
Marker m = map.addMarker(mo);
assert m != null;
m.showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(mo.getPosition(), 14));
i feel like i have defined two markers m and mo in if(){......}. but i am not sure i can't find the mistake.
if someone can help please, thenk you in advence.

passing data to infowindowclick google maps

I've declared current location latlong and selected location latlong. I want to pass these latlong to onInfoWindowClick().
When I try to use Toast to get the data that I set from marker.setTag(mLatitude) and marker.seTag(mLongitude), It give me the same data only mLongitude. Can anyone help me, please.
This is my code:
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
if (parent.getItemAtPosition(position).toString() != "-- Pilih ATM --"){
mMap.clear();
String pilih_atm = (String) parent.getItemAtPosition(position);
// Toast.makeText(getActivity(), pilih_atm, Toast.LENGTH_SHORT).show();
SQLiteDatabase db = dbHelper.getReadableDatabase();
cursor = db.rawQuery("SELECT * FROM atm WHERE atm_name = '" + pilih_atm + "'",null);
if (cursor != null){
while (cursor.moveToNext()){
title = cursor.getString(1).toString();
__global_endposition = cursor.getString(2).toString();
String[] exp_endCoordinate = __global_endposition.split(",");
double lat_endposition = Double.parseDouble(exp_endCoordinate[0]);
double lng_endposition = Double.parseDouble(exp_endCoordinate[1]);
LatLng endx = new LatLng(lat_endposition, lng_endposition);
MarkerOptions options = new MarkerOptions();
options.position(endx);
options.title(title);
options.snippet(__global_endposition);
if (title.equals("ATM BNI")){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
}else if(title.equals("ATM BCA")){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}else if(title.equals("ATM Mandiri")){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
}
Marker marker = mMap.addMarker(options);
marker.setTag(mLatitude);
marker.setTag(mLongitude);
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(getActivity()));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
// I want to get current location LatLong and selected location LatLong
// I want execute the LatLong on this method
// this just for testing
Toast.makeText(getActivity(), "LatLng: "+marker.getTag()+", "+marker.getTag(), Toast.LENGTH_SHORT).show();
}
});
}
if (!cursor.isClosed()) {
cursor.close();
cursor = null;
}
}
}
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
This is because Marker object has only one Tag object and when you call .setTag() second time, you overrides previously set tag object:
Marker marker = mMap.addMarker(options);
marker.setTag(mLatitude); // tag = mLatitude
marker.setTag(mLongitude); // tag overrides, and now tag = mLongitude
The one of solution is:
Marker marker = mMap.addMarker(options);
marker.setTag("" + mLatitude + "," + mLongitude); // tag now is string: "mLatitude, mLongitude"

Android. Google map. How to draw polygon from array

I m new to android app development.
I have WKT (POLYGON)
How to draw polygon on google map from wkt?
I try
String str;
ArrayList<String> coordinates = new ArrayList<String>();
str = tvwkt.getText().toString();
str = str.replaceAll("\\(", "");
str = str.replaceAll("\\)", "");
str = str.replaceAll("POLYGON", "");
str = str.replaceAll("POINT", "");
str = str.replaceAll(", ", ",");
str = str.replaceAll(" ", ",");
str = str.replaceAll(",,", ",");
String[] commatokens = str.split(",");
for (String commatoken : commatokens) {
coordinates.add(commatoken);
}
for (int i = 0; i < coordinates.size(); i++) {
String[] tokens = coordinates.get(i).split("\\s");
for (String token : tokens) {
listPoints.add(token);
}
}
PolygonOptions rectOptions = new PolygonOptions().addAll(listPoints).strokeColor(Color.BLUE).fillColor(Color.CYAN).strokeWidth(7);
polygon = mMap.addPolygon(rectOptions);
But its not work.
Hepl me please.
thanks.
This is a better aproach, for this sample WKT Polygon:
wkt = "POLYGON((-84.22800686845923 40.137783757219864,-82.71787050257508 33.66027041269767,-78.6190283330219 37.694486391034445,-84.22800686845923 40.137783757219864))";
We need to get the negative values, and also order correctly the lat/long
private LatLng[] getPolygonPoints() {
ArrayList<LatLng> points = new ArrayList<LatLng>();
Pattern p = Pattern.compile("(\\d*\\.\\d+)\\s(\\d*\\.\\d+)");
Matcher m = p.matcher(wkt);
String point;
while (m.find()) {
point = wkt.substring(m.start() - 1, m.end());
points.add(new LatLng(Double.parseDouble(point.split(" ")[1]), Double.parseDouble(point.split(" ")[0])));
}
return points.toArray(new LatLng[points.size()]);
}
And then draw the polygon like the last response:
public void drawPolygon() {
LatLng[] points = getPolygonPoints();
Polygon p = mMap.addPolygon(
new PolygonOptions()
.add(points)
.strokeWidth(7)
.fillColor(Color.CYAN)
.strokeColor(Color.BLUE)
);
//Calculate the markers to get their position
LatLngBounds.Builder b = new LatLngBounds.Builder();
for (LatLng point : points) {
b.include(point);
}
LatLngBounds bounds = b.build();
//Change the padding as per needed
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20, 20, 5);
mMap.animateCamera(cu);
}
I can do it.
Read LatLong from WKT and add to Array
private LatLng[] GetPolygonPoints(String polygonWkt) {
Bundle bundle = getIntent().getExtras();
wkt = bundle.getString("wkt");
ArrayList<LatLng> points = new ArrayList<LatLng>();
Pattern p = Pattern.compile("(\\d*\\.\\d+)\\s(\\d*\\.\\d+)");
Matcher m = p.matcher(wkt);
String point;
while (m.find()){
point = wkt.substring(m.start(), m.end());
points.add(new LatLng(Double.parseDouble(m.group(1)), Double.parseDouble(m.group(2))));
}
return points.toArray(new LatLng[points.size()]);
}
then draw polygon
public void Draw_Polygon() {
LatLng[] points = GetPolygonPoints(polygonWkt);
Polygon p = mMap.addPolygon(
new PolygonOptions()
.add(points)
.strokeWidth(7)
.fillColor(Color.CYAN)
.strokeColor(Color.BLUE)
);
//Calculate the markers to get their position
LatLngBounds.Builder b = new LatLngBounds.Builder();
for (LatLng point : points) {
b.include(point);
}
LatLngBounds bounds = b.build();
//Change the padding as per needed
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20,20,5);
mMap.animateCamera(cu);
}
finally
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(MAP_TYPE_HYBRID);
mMap.getUiSettings().setRotateGesturesEnabled(false);
mMap.getUiSettings().setMapToolbarEnabled(false);
LatLng[] points = GetPolygonPoints(polygonWkt);
if (points.length >3){
Draw_Polygon();
}
else {
Add_Markers();
}
}

Draw Routes between multiple points on map

I am new to android. I want to draw routes between multiple markers. I a, getting latitude, longitude and datetime from server. Now i want to show route between the points. I have stored them in arraylist. Here is how i am getting the points in async task doInBackground().
newLatt= new ArrayList<String>();
newLongg= new ArrayList<String>();
newdatTime= new ArrayList<String>();
JSONArray arr = new JSONArray(strServerResponse);
for (int i = 0; i < arr.length(); i++) {
JSONObject jsonObj1 = arr.getJSONObject(i);
String status = jsonObj1.optString("status");
if (status!="false"){
Pojo pojo = new Pojo();
String latitude = jsonObj1.optString("Latitude");
String longitude = jsonObj1.optString("Longitude");
String date_time = jsonObj1.optString("date_time");
newLatt.add(latitude);
newLongg.add(longitude);
newdatTime.add(date_time);
}else {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
#Override
public void run() {
AlertDialog alertDialog = new AlertDialog.Builder(
MapActivity.this).create();
alertDialog.setMessage("Locations Not Available");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
);
}
and in postExecute() method i am showing markers
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = supportMapFragment.getMap();
map.setMyLocationEnabled(true);
if (newLatt.size()>0){
for (int i = 0; i < newLatt.size(); i++) {
Double lati = Double.parseDouble(newLatt.get(i));
Double longi = Double.parseDouble(newLongg.get(i));
String dattme = newdatTime.get(i);
dest = new LatLng(lati, longi);
if (map != null) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(dest);
map.moveCamera(CameraUpdateFactory.newLatLng(dest));
map.animateCamera(CameraUpdateFactory.zoomTo(15));
markerOptions.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED));
markerOptions.title("" + dattme);
map.addMarker(markerOptions);
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
return false;
}
});
UPDATE
PolylineOptions rectOptions = new PolylineOptions();
//this is the color of route
rectOptions.color(Color.argb(255, 85, 166, 27));
LatLng startLatLng = null;
LatLng endLatLng = null;
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = supportMapFragment.getMap();
map.setMyLocationEnabled(true);
if (newLatt.size()>0){
for (int i = 0; i < newLatt.size(); i++) {
Double lati = Double.parseDouble(newLatt.get(i));
Double longi = Double.parseDouble(newLongg.get(i));
String dattme = newdatTime.get(i);
dest = new LatLng(lati, longi);
if (map != null) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(dest);
map.moveCamera(CameraUpdateFactory.newLatLng(dest));
map.animateCamera(CameraUpdateFactory.zoomTo(15));
markerOptions.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED));
markerOptions.title("" + dattme);
map.addMarker(markerOptions);
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
return false;
}
});
LatLng latlng = new LatLng(lati,
longi);
if (i == 0) {
startLatLng = latlng;
}
if (i == newLatt.size() - 1) {
endLatLng = latlng;
}
rectOptions.add(latlng);
String url = getDirectionsUrl(startLatLng, endLatLng);
DownloadTask downloadTask = new DownloadTask();
downloadTask.execute(url);
}
}
map.addPolyline(rectOptions);
getDirections:
private String getDirectionsUrl(LatLng origin, LatLng dest) {
// Origin of route
String str_origin = "origin=" + origin.latitude + ","
+ origin.longitude;
// Destination of route
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
// Sensor enabled
String sensor = "sensor=false";
// Building the parameters to the web service
String parameters = str_origin + "&" + str_dest + "&" + sensor;
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/directions/"
+ output + "?" + parameters;
return url;
}
In your postExecute add the following code to add ploylines on the map.
PolylineOptions rectOptions = new PolylineOptions();
//this is the color of route
rectOptions.color(Color.argb(255, 85, 166, 27));
LatLng startLatLng = null;
LatLng endLatLng = null;
for (int i = 0; i < newLatt.size(); i++) {
Double lati = Double.parseDouble(newLatt.get(i));
Double longi = Double.parseDouble(newLongg.get(i));
LatLng latlng = new LatLng(lati,
longi);
if (i == 0) {
startLatLng = latlng;
}
if (i == jArr.length() - 1) {
endLatLng = latlng;
}
rectOptions.add(latlng);
}
map.addPolyline(rectOptions);
Happy coding...
Android does not provide embedded direction service in google map api. To draw route between points you must use google direction services REST API .
You can get complete code and description from http://wptrafficanalyzer.in/blog/drawing-driving-route-directions-between-two-locations-using-google-directions-in-google-map-android-api-v2/
ArrayList<LatLng> points = null;
PolylineOptions lineOptions = null;
MarkerOptions markerOptions = new MarkerOptions();
// Traversing through all the routes
for(int i=0;i<result.size();i++){
points = new ArrayList<LatLng>();
lineOptions = new PolylineOptions();
// Fetching i-th route
List<HashMap<String, String>> path = result.get(i);
// Fetching all the points in i-th route
for(int j=0;j<path.size();j++){
HashMap<String,String> point = path.get(j);
double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);
points.add(position);
}
// Adding all the points in the route to LineOptions
lineOptions.addAll(points);
lineOptions.width(2);
lineOptions.color(Color.RED);
}
// Drawing polyline in the Google Map for the i-th route
map.addPolyline(lineOptions);

How to get the latitude and longitude of an image in sdcard to my application?

From my application I can open gallery. Is there any way to get latitude and longitude of any selected image in gallery to my application?
You can actually use a "buildin" function:
ExifInterface exif = new ExifInterface(path);
float[] latLong = new float[2];
boolean hasLatLong = exif.getLatLong(latLong)
if (hasLatLong) {
System.out.println("Latitude: " + latLong[0]);
System.out.println("Longitude: " + latLong[1]);
}
Maybe is something new, but I think is much more convenient than the accepted answer.
You Should Go with ExifInterface class to read various EXIF metadata from Images:
Example :
ExifInterface exif = new ExifInterface(filepath);
exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
Edited :
Now Here you will get lat-long as Below format.
lat = 30/1,12/1,34/1,
long=81/1,22/1,41/1
To Convert this into Real Values this Blog Helped Me.
we need to do conversion from degree, minute, second form to GeoPoint form.
By Below Way you can Do it.
String LATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
String LATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
String LONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
String LONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
// your Final lat Long Values
Float Latitude, Longitude;
if((LATITUDE !=null)
&& (LATITUDE_REF !=null)
&& (LONGITUDE != null)
&& (LONGITUDE_REF !=null))
{
if(LATITUDE_REF.equals("N")){
Latitude = convertToDegree(LATITUDE);
}
else{
Latitude = 0 - convertToDegree(LATITUDE);
}
if(LONGITUDE_REF.equals("E")){
Longitude = convertToDegree(LONGITUDE);
}
else{
Longitude = 0 - convertToDegree(LONGITUDE);
}
}
private Float convertToDegree(String stringDMS){
Float result = null;
String[] DMS = stringDMS.split(",", 3);
String[] stringD = DMS[0].split("/", 2);
Double D0 = new Double(stringD[0]);
Double D1 = new Double(stringD[1]);
Double FloatD = D0/D1;
String[] stringM = DMS[1].split("/", 2);
Double M0 = new Double(stringM[0]);
Double M1 = new Double(stringM[1]);
Double FloatM = M0/M1;
String[] stringS = DMS[2].split("/", 2);
Double S0 = new Double(stringS[0]);
Double S1 = new Double(stringS[1]);
Double FloatS = S0/S1;
result = new Float(FloatD + (FloatM/60) + (FloatS/3600));
return result;
};
#Override
public String toString() {
// TODO Auto-generated method stub
return (String.valueOf(Latitude)
+ ", "
+ String.valueOf(Longitude));
}
public int getLatitudeE6(){
return (int)(Latitude*1000000);
}
public int getLongitudeE6(){
return (int)(Longitude*1000000);
}
the exif.getLatLong(float[]) is now deprecated, you can use a better method which returns a double[] :
ExifInterface exifInterface = new ExifInterface(file);
double[] latlng = exifInterface.getLatLong();
if (latlng != null) {
Double currentLatitude = latlng[0];
Double currentLongitude = latlng[1];
Log.d("Debug", "Exif : latitude: " + currentLatitude + ", longitude: " + currentLongitude)
}
Happy coding.

Categories

Resources