package cgeo.geocaching.apps.cache.navi;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.Waypoint;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.utils.Log;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

class GoogleMapsApp extends AbstractPointNavigationApp {

    GoogleMapsApp() {
        super(getString(R.string.cache_menu_map_ext), R.id.cache_app_google_maps, null);
    }

    @Override
    public boolean isInstalled() {
        return true;
    }

    @Override
    public void navigate(Activity activity, Geopoint point) {
        navigate(activity, point, activity.getString(R.string.waypoint));
    }

    private static void navigate(Activity activity, Geopoint point, String label) {
        try {
            final String geoLocation = "geo:" + point.getLatitude() + "," + point.getLongitude();
            final String query = point.getLatitude() + "," + point.getLongitude() + "(" + label + ")";
            final String uriString = geoLocation + "?q=" + Uri.encode(query);
            activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uriString)));
            return;
        } catch (RuntimeException e) {
            // nothing
        }
        Log.i("GoogleMapsApp.navigate: No maps application available.");

        ActivityMixin.showToast(activity, getString(R.string.err_application_no));
    }

    @Override
    public void navigate(Activity activity, Geocache cache) {
        navigate(activity, cache.getCoords(), cache.getName());
    }

    @Override
    public void navigate(Activity activity, Waypoint waypoint) {
        navigate(activity, waypoint.getCoords(), waypoint.getName());
    }
}

@@ -212,24 +212,133 @@
 t.Geopoint;%0A
+import cgeo.geocaching.geopoint.GeopointFormatter;%0Aimport cgeo.geocaching.geopoint.GeopointFormatter.Format;%0A
 import cgeo.
@@ -953,16 +953,213 @@
   try %7B%0A
+            String latitude = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, point);%0A            String longitude = GeopointFormatter.format(Format.LON_DECDEGREE_RAW, point);%0A
         
@@ -1198,35 +1198,24 @@
 geo:%22 + 
-point.getL
+l
 atitude
-()
  + %22,%22 +
@@ -1215,34 +1215,25 @@
 + %22,%22 + 
-point.getL
+l
 ongitude
 ();%0A    
@@ -1224,18 +1224,16 @@
 ongitude
-()
 ;%0A      
@@ -1263,27 +1263,16 @@
 y = 
-point.getL
+l
 atitude
-()
  + %22
@@ -1280,26 +1280,17 @@
 %22 + 
-point.getL
+l
 ongitude
 () +
@@ -1285,18 +1285,16 @@
 ongitude
-()
  + %22(%22 +

fix #3731: use formatted numbers when calling navigation