Skip to content

Instantly share code, notes, and snippets.

@muratcanbur
Created November 29, 2014 19:34
Show Gist options
  • Select an option

  • Save muratcanbur/1150dc5b2bfc17e8d0e3 to your computer and use it in GitHub Desktop.

Select an option

Save muratcanbur/1150dc5b2bfc17e8d0e3 to your computer and use it in GitHub Desktop.
if you don't want to integrate Google Maps to in your app, use this method
private void launchGoogleMaps(Context context, double latitude,
double longitude) {
try {
String format = "geo:0,0?q=" + Double.toString(latitude) + ","
+ Double.toString(longitude);
Uri uri = Uri.parse(format);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (Exception e) {
// maps application is unavailable, fallback to browser
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(String.format(
"http://maps.google.com/maps?q=%1$s,%2$s&z=15",
latitude, longitude)));
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment