Android Code Snippet Start Map Intent for Google And Waze

Object Navigate to street address or geo Coordinates
The following procedure will start the mapping intents for google or waze

B4X:
'Example
'NavigateToStreetAdress("Waze","124 main st,somecity,somestate,somezipcode","0","0")

Sub NavigateToStreetAdress(provider As String,sAddress As String, latitude As String, longitude As String)
    'google intent
    'Variables
    'Provider Send Google or Waze
    'sAddress Send fully qualified address Example:123 Main st,someCity,SomeState,Somezipcode
    'latitude send latitude
    'longitude send longitude
  
    'Google mapping is already included on android phones
    If provider = "Google" Then
        Dim mapIntent As Intent
        Dim gURI As String
        If latitude.Contains(".") = True And longitude.Contains(".") = True Then
            gURI="google.navigation:q=" & latitude & "," & longitude
        Else
            gURI = "google.navigation:q=" & sAddress
        End If
      
        mapIntent.Initialize(mapIntent.ACTION_VIEW, gURI)
        mapIntent.SetComponent("googlemaps")
        StartActivity(mapIntent)
    End If
  
    'Waze must be installed to use it if installed the intent will start else it will send you to the market to install waze
    If provider = "Waze" Then
        'Waze intent
        'use geo address waze://?ll & latitude & "," & longitude
        'use address location waze://?q= & sAddress
        Try
            Dim mIntent As Intent
        Dim wURI As String
        If latitude.Contains(".") = True And longitude.Contains(".") = True Then
            wURI = "waze://?ll=" & latitude & "," & longitude & "&navigate=yes"
            Else
            wURI = "waze://?q=" & sAddress & "&navigate=yes"
        End If
         Log(wURI)
        'wURI = "waze://?q=" & sAdress & "&navigate=yes"
        mIntent.Initialize(mIntent.ACTION_VIEW, wURI)
        StartActivity(mIntent)
        Catch
          
            If LastException.Message.Contains("ActivityNotFoundException") = True Then
                If Msgbox2("This Application Uses Waze Mapping and must be installed to use the mapping features", "Install Waze", "Yes", "Cancel", "", Null) = DialogResponse.POSITIVE Then
          
                'Waze Not Installed
                Dim nIntent As Intent
                Dim nUri As String
                nUri = "market://details?id=com.waze"
                nIntent.Initialize(nIntent.ACTION_VIEW, nUri)
                StartActivity(nIntent)
                Else
                    Return
                End If
            Else
                Log(LastException)
            End If
          
        End Try
    End If
  
End Sub

Dependencies: NONE
Tags: Navigation,Mapping,Intents,Google,Waze
 
Top