UserGuide

Web Map Viewer

From Xojo Documentation

The Map Viewer uses Google Maps to display a map that is centered at a user-specified location. The location can be specified by its latitude and longitude coordinates or by a location, such as “Boston, MA”. You will typically also use the WebMapLocation class with Map Viewer.

fa-exclamation-circle-32.png
As of June 2018, Google Maps requires an API Key. You will need to set the APIKey property to your API Key in order for WebMapViewer to display any maps.

Commonly used properties and methods are listed below. For the complete list, refer to WebMapViewer in the Language Reference.

Properties

APIKey - The Google Maps API key.

Latitude, Longitude - Allow you to specify or check the latitude and longitude of the center of the displayed map. Call Update to relocate the map after making changes to these values.

MapType - Used to specify the type of map that is displayed: Roadmap, Satellite, Hybrid, Terrain.

Methods

AddLocation - Adds a WebMapLocation to the map. This displays a "pin" at the location.

GoToLocation - Centers the map on the passed WebMapLocation.

RemoveLocation - Removes a WebMapLocation "pin" from the map.

Web Map Location

Locations are created by using the WebMapLocation class.

You can use the Constructor to create a location based on a text address or by specific latitude and longitude as shown below.

Usage

Be sure to set your API key before attempting to display a map with code in its Open event:

Me.APIKey = "<YourGoogleMapsAPIKey>"

This creates a location and displays it on a Map Viewer:

Var location As New WebMapLocation("Fenway Park, Boston, MA")
MapViewer1.GoToLocation(location)

This displays a location entered by the user (in the LocationField TextField) on a Map Viewer:

Try
Var location As New WebMapLocation(LocationField.Value)
MapViewer1.GoToLocation(location)
Catch e As NilObjectException
MessageBox("Invalid location.")
End Try

Example Projects

  • Examples/Sample Applications/EddiesElectronics/Web/EEWeb

See Also

WebMapViewer, WebMapLocation classes; Get Google Maps API Key