This example shows how to call the native map app (Google Map for Android, Map for Apple) from your own app with two address or geolocation points, and show the route between them, either by walking, driving or transit.
Suppose we have a panel where the user enters either all or part of this information:
- the source address or a geolocation point
- the target address or a geolocation point
- the transportation mode, the could be one of these:
- d - Driving/Car
- w - Walking
- r - Transit
Then using the Interop external object we can call the native map app to show that navigation.
The code will be something like this:
&Saddr= &Saddr.Replace(' ','+') //blanks in address does not work
&Daddr= &Daddr.Replace(' ','+')
&url = format('saddr=%1&daddr=%2&dirflg=%3', &Saddr.Trim(), &Daddr.Trim(), &TrasportationMode.Trim())
&SmartDeviceType = ClientInformation.DeviceType
If &SmartDeviceType = SmartDeviceType.Android
Interop.Open("http://maps.google.com/maps?"+&url)
else
Interop.Open("http://maps.apple.com/?"+&url)
endif
Notes:
- All addresses must be encoded. Spaces in the string can be encoded with %20 or replaced with the plus sign (+). That is the reason for the first two lines.
- There is no common URI scheme to call the Map App indistinctly from Android or iOS, so this solution is based on creating a Http link that depends on each platform.
Download the example from here (xpz for GeneXus v15)
These links provide more URI format:
If your app is only for Android (i.e., no cross-platform), the 'geo' scheme mentioned in the last link could be useful in case the device has more than one map app. For instance:
Interop.Open("geo:" &location)
Interop.Open("geo:0,0?q=" + &address)
Category:Geography?