1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
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.geopoint.GeopointFormatter;
import cgeo.geocaching.geopoint.GeopointFormatter.Format;
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 {
String latitude = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, point);
String longitude = GeopointFormatter.format(Format.LON_DECDEGREE_RAW, point);
final String geoLocation = "geo:" + latitude + "," + longitude;
final String query = latitude + "," + longitude + "(" + 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());
}
}
|