Main Content

Display Data on OpenStreetMap Basemap

This example shows how to display a driving route and vehicle positions on an OpenStreetMap® basemap.

Add the OpenStreetMap basemap to the list of basemaps available for use with the geoplayer object. After you add the basemap, you do not need to add it again in future sessions.

name = 'openstreetmap';
url = 'https://a.tile.openstreetmap.org/${z}/${x}/${y}.png';
copyright = char(uint8(169));
attribution = copyright + "OpenStreetMap contributors";
addCustomBasemap(name,url,'Attribution',attribution)

Load a sequence of latitude and longitude coordinates.

data = load('geoRoute.mat');

Create a geographic player. Center the geographic player on the first position of the driving route and set the zoom level to 12.

zoomLevel = 12;
player = geoplayer(data.latitude(1),data.longitude(1),zoomLevel);

Figure Geographic Player contains an axes object with type geoaxes. The geoaxes object is empty.

Display the full route.

plotRoute(player,data.latitude,data.longitude);

Figure Geographic Player contains an axes object with type geoaxes. The geoaxes object contains 2 objects of type line, scatter.

By default, the geographic player uses the World Street Map basemap ('streets') provided by Esri®. Update the geographic player to use the added OpenStreetMap basemap instead.

player.Basemap = 'openstreetmap';

Figure Geographic Player contains an axes object with type geoaxes. The geoaxes object contains 2 objects of type line, scatter.

Display the route again.

plotRoute(player,data.latitude,data.longitude);

Figure Geographic Player contains an axes object with type geoaxes. The geoaxes object contains 4 objects of type line, scatter.

Display the positions of the vehicle in a sequence.

for i = 1:length(data.latitude)
   plotPosition(player,data.latitude(i),data.longitude(i))
end

Figure Geographic Player contains an axes object with type geoaxes. The geoaxes object contains 6 objects of type line, scatter, text.

See Also

| | | |