Created
November 29, 2014 19:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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