Skip to content

Get There From Here with the MobileMapViewer for Android

A new control added to Android for Xojo 2025r2 is MobileMapViewer. This control uses the Google Maps SDK to display mapping data in your apps.

Before you can use MobileMapViewer you will need to have a Google Maps account configured so that you can generate an API Key. Instructions for doing this on available from Google: Google Maps Platform, Get Google Maps API Key.

Google Maps is not free to use. Although there is some free usage available for testing your app, your account does get billed based on usage once the small amount of free testing credits are used up.

When you have your API Key, you can add it to your Xojo project using a new App property. Select App in the Navigator and in the Inspector, put the key in the Google Maps API Key field. Note that the key is not saved with text projects and is instead saved as part of the UI state file that is local to the development machine. This prevents the key from being accidently committed to a source code repository.

With the configuration work out of the way, you can now use the control. Drag a MobileMapViewer from the Library onto a screen. When you run the project you’ll see an interactive map that you can swipe, zoom and move around as you like.

This code shows Fenway Park in Boston:

FenwayLocation = New MapLocation("Fenway Park, Boston, MA USA")
FenwayLocation.Title = "Fenway Park"

MapViewer1.ZoomRadius = 5
MapViewer1.GoToLocation(FenwayLocation) // Center map within radius km

MapViewer1.AddLocation(FenwayLocation) // Drop a pin

The MobileMapVIewer API matches what has already been in use for iOS. You can also use the MapLocation class to track specific locations. Although the overall API matches what has been used for iOS, there is one exception: MapLocation.PointsOfInterest() is not yet implemented. Implementing this requires another Google SDK and API Key (the Places API) and is being reviewed for a future release. We may also consider adding alternative mapping engines as well.

Note: You can’t get there from here is an old Maine saying.

Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at Goto 10 and on Mastodon @lefebvre@hachyderm.io.