Skip to content

Instantly share code, notes, and snippets.

@moisesaq
Last active July 15, 2020 04:43
Show Gist options
  • Save moisesaq/5433b5678f0d7eb7fdce663c6c24a23c to your computer and use it in GitHub Desktop.
Save moisesaq/5433b5678f0d7eb7fdce663c6c24a23c to your computer and use it in GitHub Desktop.
Simple builder to create two intent for Google Maps and Waze
class NavigationBuilder {
fun mapsIntent(location: Location, address: String): Intent {
val uri = Uri.parse("geo:${location.lat},${location.lng}?q=$address")
return Intent(Intent.ACTION_VIEW, uri).apply { setPackage("com.google.android.apps.maps") }
}
fun wazeIntent(location: Location, address: String): Intent {
val uri = Uri.parse("https://waze.com/ul?q=$address&ll=${location.lat},${location.lng}&navigate=yes")
return Intent(Intent.ACTION_VIEW, uri)
}
}
data class Location(val lat: Double, val lng: Double)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment