Android Tutorial Showing Google turn by turn

Hi,

Below some sample code to show directly Turn by Turn navigation instead of map:

Sub ShowNavigation (Latitude As String,Longitude As String)
'google place, just show map
Dim mapIntent As Intent
Dim geoURI As String
geoURI="google.navigation:q=" & Latitude & "," & Longitude
mapIntent.Initialize(mapIntent.ACTION_VIEW,geoURI)
mapIntent.SetComponent("googlemaps")
StartActivity(mapIntent)
End Sub

I use this in a static module.

Have fun!
 

rbsoft

Active Member
Licensed User
Longtime User
And this will calculate and show a route between two street adresses:

B4X:
Sub CalcRouteAdresses()
    Dim mapIntent As Intent
    Dim geoURI As String
    Dim Start, Dest As String
   
    Start = "Am Nordbad 5,Bochum,44805"
    Dest = "Castroper Str. 475,Bochum,44805"
    geoURI="http://maps.google.com/maps?saddr=" & Start & "&daddr=" & Dest
    mapIntent.Initialize(mapIntent.ACTION_VIEW,geoURI)
    mapIntent.SetComponent("googlemaps")
    StartActivity(mapIntent)
End Sub

Rolf
 

AlteregoHR

Member
Licensed User
Longtime User
Thank you,
Is it possible to specify that it doesnt ask for browser or maps but to use just maps?
Thanks,
 

AlteregoHR

Member
Licensed User
Longtime User
What I asked there and now asking here is that i would like to open navigation directly in maps not for andorid to ask mi if I wanted maps or browser.
Your sample did the same ask for one or the other. I dont want to give that decision to user. If ti doesnt have maps instaled than he cant use this feature.
I find this thread and example was exectly as I use google maps so I asked in this thread also. Sorry.
 

ThePuiu

Active Member
Licensed User
Longtime User
Hi, Is it possible to display a Google map with the route between my current position and a destination on an address or geographic coordinates in a WebView (instead of a Intent)?
 

sdujolo

Member
Licensed User
Longtime User
Is there any way to ask for distance between to addresses and get the result back with out open a external app?
 

rbsoft

Active Member
Licensed User
Longtime User
Yes that is possible. You would have to insert the proper Http code. This would be the Http code for a route between two adresses in my hometown.

https://www.google.com/maps/preview...89!3d51.4897419!3m2!1i1486!2i848!4f13.1&fid=0

This page gives you some insight how to get to this. The site has a lot of JavaScript code eamples:

http://econym.org.uk/gmap/directions.htm

and here is the officeal Maps Java Script Documentation:

https://developers.google.com/maps/documentation/javascript/v2/reference?hl=de&csw=1#GDirections

Rolf
 

udg

Expert
Licensed User
Longtime User
To get a street adress from the coordinates (reverse geocoding) you probably would need to use Google's geocode service This might be an interesting link for it: Google Geo Developers Blog: Geocoding... in Reverse!
Rolf

Hi Rolf,

I'd like to design a very basic app where the user can record its current position in order to retrieve it later.
Something like "where did I park my car?".
Now, I'd like to enter the current position using two distinct methods: GPS coordinates and street address.
What I'd really like to accomplish is automatic conversion of data between those two methods, so if the user gets a reading from its GPS than a street address is shown on display.
I read the above linked blog but its out of my reach. Is there anything easier to use or an easy wrapper around that? TIA

Umberto
 

rbsoft

Active Member
Licensed User
Longtime User
Hi Umberto,

here is a little example code how you could achieve that. You will need to use the Gps and Geocoder Library (as Martin mentioned already).

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Gps1 As GPS
    Dim cLat As String
    Dim cLng As String
    Dim Geocoder1 As Geocoder
End Sub

B4X:
Sub GPS_LocationChanged (Location As Location)
    'This will keep the coordinates uptodate
 
    If Location.AccuracyValid = True Then
        cLat = NumberFormat2(Location.Latitude,1,9,9,False)
        cLng = NumberFormat2(Location.Longitude,1,9,9,False)
        'Log("Coord: " & cLat & "/" & cLng)
    End If
End Sub

B4X:
Sub GetStreetAdress()
    Dim Results As Address
    Dim Address1 As Address
    Dim geoAdress As String
 
    Try
        Results = Geocoder1.GetFromLocation(cLat, cLng, 5)
        Address1 = Results(0)
        If Address1.AddressLines.Size > 0 Then
            Log("geoResults: " & Results(0))
            geoAdress = Address1.Thoroughfare & _
                        Address1.FeatureName & _
                        "#" & Address1.Locality
            Log(geoAdress)
            Msgbox(geoAdress,"Bingo")
        End If
    Catch
        ToastMessageShow("No street adress available!",True)
    End Try
End Sub

These two little functions should get you going.

Rolf
 
Last edited:

udg

Expert
Licensed User
Longtime User
Martin, Rolf,
thank you both. I wasn't aware of the Geocoder library at all and the code above is going to solve my problem.
Well, time to go back to experiment and learn..

Umberto
 

laviniut

Active Member
Licensed User
Longtime User
I need to make an application for visually impaired people for my PhD. For navigation part of application, I take start address from GPS and destination address from voice recognition module.
So I have some questions:
1. can i start google navigation turn-by-turn in background ?
or
2. can i set the route in google maps or navigation and after that to get only directions to follow every corner on that route ?

can somebody help me ? please!
 
Last edited:

laviniut

Active Member
Licensed User
Longtime User
how can i set google navigation to speak more (start position, go there...) ?
 

laviniut

Active Member
Licensed User
Longtime User
How can i convert from GPS coordinates to lat lon in decimal degrees ?

This would show a route between two coordinates. The routine will ask if you want to use the browser or the maps application. Works in both.

B4X:
Sub CalcRoute()
    Dim mapIntent As Intent
    Dim geoURI As String
    Dim Lat1,Lat2,Lon1,Lon2 As String
 
    Lat1 = "51.12345"
    Lon1 = "6.12345"
    Lat2 = "51.54321"
    Lon2 = "6.54321"
 
    geoURI="http://maps.google.com/maps?saddr=" & Lat1 & "," & Lon1 & "&daddr=" & Lat2 & "," & Lon2
    mapIntent.Initialize(mapIntent.ACTION_VIEW,geoURI)
    mapIntent.SetComponent("googlemaps")
    StartActivity(mapIntent)
End Sub

Rolf
 

Shay

Well-Known Member
Licensed User
Longtime User
Is there a way after I planned the route, and google map is open , and I am driving to change the route on the fly
and second question, is it possible again on the fly to add markers (not route, just my own POI - using some bitmap)
 

jsanchezc

Member
Licensed User
Longtime User
Try this Sub:
B4X:
Sub Grados2Decimal(Tx As String) As Double
   Dim Resultado As Double=0
   Dim Datos() As String
 
   Tx=Tx.Replace("º"," ")
   Tx=Tx.Replace("'"," ")
   Tx=Tx.Replace("´"," ")

   Tx=Tx.Replace(Chr(34)," ")

   Tx=Tx.Replace("  "," ")
   Tx=Tx.Replace("  "," ")
   Tx=Tx.Replace("  "," ")
   Tx=Tx.Replace("  "," ")
   Tx=Tx.Replace("  "," ")
   Tx=Tx.Replace("  "," ")
 
   Datos=Regex.Split (" " , Tx)
   If Datos.length>0 Then
      Resultado=Datos(0)
      If Datos.length> 1 Then
         Resultado=Resultado + (Datos(1) /60)
         If Datos.Length > 2 Then
            Resultado=Resultado + (Datos(2) /3600)
         End If
       End If
    End If
    Return Round2(Resultado,6)
End Sub
How can i convert from GPS coordinates to lat lon in decimal degrees ?
 

Troberg

Well-Known Member
Licensed User
Longtime User
I'm not near my dev computer for a while, so I can't try this now, but is there some way to get just the turn by turn instructions at apropriate times, no map (although, I might want to switch to the map occasionally)?

For example (just general examples, not word by word):

* Turn left in 100m
* Take the third exit in the roundabout in 150m
* Take the right lane onto the highway

That kind of stuff. Something like this event, fired whenever there is a new turn instruction (once again, just a general idea example to make it clearer what I mean, not a specification):

Sub Map_NewDirection(Symbol as Bitmap, Text as string, Distance as int)

I want to display navigation instructions without devoting much screen space for it, just a narrow banner at the edge of the screen. It would be immensely useful for me.
 

Gabriel Conti

Member
Licensed User
Longtime User
Rolf..... excelente post!!!! muchas gracias estaba trabajando en una aplicación muy similar
Gracias
 
Top