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 and WebDeviceLocation classes 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 events, properties and methods are listed below. For the complete list, refer to WebMapViewer in the Language Reference.

Events

CenterChanged

Called when the map has been re-centered.

TypeChanged

Called when the type of the map has changed.

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.

Update

Centers the map after changes to Latitude and Longitude.

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

Web Map Viewer

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:

Dim 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
Dim location As New WebMapLocation(LocationField.Text)
MapViewer1.GoToLocation(location)
Catch e As NilObjectException
MsgBox("Invalid location.")
End Try

Example Projects

  • Examples/Sample Applications/EddiesElectronics/Web/EEWeb
  • Examples/Sample Applications/MapLocation
  • Examples/Web/Controls/MapViewer/MapViewer

See Also

WebMapViewer, WebMapLocation classes; UserGuide:Web UI topic; Get Google Maps API Key