Android Question Open Maps from the app starting from my location to another

Mattiaf

Active Member
Licensed User
Hey I'm trying to open maps from my app and to set already the coordinates.
Starting from point A ( My gps location ) to a point B.

I found this @Erel code
Erel Code

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Wait For MapFragment1_Ready
   gmap = MapFragment1.GetMap
   If gmap.IsInitialized Then
     Do While gmap.MyLocation.IsInitialized = False
       Sleep(100)
     Loop
     Dim cp As CameraPosition
     cp.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, 5)
     gmap.MoveCamera(cp)
   End If
End Sub

but I don't know how to set the point B in this code..
I found this code
B4X:
Private i As Intent
        Private city As String
        Private province As String
        Private street As String
        Private HouseNumber As String
        Private MapURL As String
        city = "Milano"
        province = "MI"
        street = "Via Manzoni"
        HouseNumber = "10"
        MapURL = "http://maps.google.com/maps?saddr=" & city & "," & province & ",&daddr=" & street & " " & HouseNumber
        
        i.Initialize(i.ACTION_VIEW, MapURL)
   i.SetComponent("com.google.android.apps.maps/com.google.android.maps.MapsActivity")
        StartActivity(I)

but to be honest, I don't know how to implement both together..
Thanks
 
Solution
I solved! it was easier than i thought!
using
B4X:
Private MapURL As String= "http://maps.google.com/maps?daddr=" & DestinationAddress

will open maps and ask you straight away to enable gps!

DonManfred

Expert
Licensed User
Longtime User
have you tried to give lat and lon instead of a address?

latitude,longitude
 
Upvote 0

Mattiaf

Active Member
Licensed User
have you tried to give lat and lon instead of a address?

latitude,longitude
What do you mean? Both codes are working, but I would like them to work together.
So for example, I want to press a button where it opens google maps and the first location is my gps location and the second one is a qwery of a location
 
Upvote 0

Mattiaf

Active Member
Licensed User
As I said, both codes work fine! I just don't know how to make them work together. How can I with the following code
B4X:
 Wait For MapFragment1_Ready
   gmap = MapFragment1.GetMap
   If gmap.IsInitialized Then
     Do While gmap.MyLocation.IsInitialized = False
       Sleep(100)
     Loop
     Dim cp As CameraPosition
     cp.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, 5)
     gmap.MoveCamera(cp)
   End If

set saddr with my location?
 
Upvote 0

Mattiaf

Active Member
Licensed User
You need to be using the Geocoding API.


This will convert an address to a lat/long you can then use the lat/long to change the camera position.
Hey Andrew thanks for your reply.
Can i ask you if we can make things easier?Erel code is already enabling gps, it wouldn't be possible to do something like

B4X:
Private i As Intent
        Private MapURL As String
       Private DestinationAddress as string= "ISTITUTO SUPERIORE ELEONORA D'ARBOREA VIA CARBONI-BOI/ANGOLO VIA AMAT"
        Private MapUrl as string= "http://maps.google.com/maps?saddr=" my location & DestinationAddress
        
        i.Initialize(i.ACTION_VIEW, MapURL)
   i.SetComponent("com.google.android.apps.maps/com.google.android.maps.MapsActivity")
        StartActivity(I)

without using the geo api? Much thanks...
 
Upvote 0

Mattiaf

Active Member
Licensed User
I solved! it was easier than i thought!
using
B4X:
Private MapURL As String= "http://maps.google.com/maps?daddr=" & DestinationAddress

will open maps and ask you straight away to enable gps!
 
Upvote 0
Solution
Top