Skip to content

More Options with Maps on iOS

Starting with Xojo 2023 Release 4 Xojo improved areas of the MobileMapViewer and MobileLocation classes on iOS. This release includes a new way to add locations to a Map itself, plus PointsofInterest and DistanceTo methods.

Adding New Locations

Previously, the only way to add new locations to a MobileMapViewer on iOS was via code. Starting with Xojo 2023r4, the user can do this with a long press on the Map control itself. This will raise the new Pressed event handler providing the latitude and longitude parameters and allowing you to use these values to add a new MapLocation instance from the values; for example:

Var nl As New MapLocation( latitude, longitude )
MapViewer1.AddLocation nl

In addition, the user can now select any of the Pins previously added to the Map control and drag them to a new destination in the map.

Points of Interest

Another new feature for your Map-based iOS apps is the PointsOfInterest method for the MapLocation class. When this method is called on a MapLocation instance it will return an array of strings with the points of interest that are nearby. For example, relevant landscapes, monuments, museums, etc., just the kind of information the user may be interested in when walking around or when selecting any of the Pins in your app.

This line of code will retrieve points of interest (if any) from a MapLocation instance pointed by the “nl” variable:

Var pois() As String = nl.PointsOfInterest

Track the Distance

Another new method added to the MapLocation class on iOS is DistanceTo. This method is called on a MapLocation instance, expect to receive another MapLocation instance as the parameter. It will return a double value representing the distance, in kilometers, between the locations.

For example, this code added to the Pressed event of the MobileMapViewer will add the distance between a new location where the user long presses on the Map and a previous location saved in a Screen object property:

Var nl As New MapLocation( latitude, longitude )
MapViewer1.AddLocation nl

If PreviousLocation <> Nil Then
distanceLabel.Text = nl.DistanceTo(PreviousLocation).toString
End If

PreviousLocation = nl

In Summary

With these additions and improvements available in Xojo 2023r4 for MobileMapViewer and MobileLocation on iOS, we expect you will be able to provide even more power and flexibility to your Map-based iOS apps! We can’t wait to see what you do with these!

Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón, Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at @XojoES or on the Xojo Forum.