Function Repository Resource:

OpenWebMap

Source Notebook

Open a geographic position in an online mapping service

Contributed by: Jesse Friedman

ResourceFunction["OpenWebMap"][pos]

opens pos in an online mapping service using your default web browser.

ResourceFunction["OpenWebMap"][pos,"URL"]

returns the URL that would be opened by ResourceFunction["OpenWebMap"][pos].

Details and Options

pos can be any of the following geographic position types: GeoPosition, GeoPositionXYZ, GeoPositionENU, GeoGridPosition.
pos can be an entity with a suitable position property, in which case ResourceFunction["OpenWebMap"][pos] is equivalent to ResourceFunction["OpenWebMap"][GeoPosition[pos]].
pos can be a pair {lat,lon} of geographic coordinates.
ResourceFunction["OpenWebMap"][pos,"URL"] returns a URL object.
ResourceFunction["OpenWebMap"][pos] is equivalent to SystemOpen[ResourceFunction["OpenWebMap"][pos]]
If pos contains more than one coordinate, the mean of the coordinates is taken.
The following options are supported by ResourceFunction["OpenWebMap"]:
GeoBackgroundAutomatictype of map
GeoServer"Google"mapping service to use
GeoZoomLevelAutomaticzoom level of map
The following settings are supported for the GeoServer option:
Automaticequivalent to "Google"
"Bing"Microsoft Bing Maps »
"Google"Google Maps »
"GoogleEarth"Google Earth for web »
"HERE"HERE WeGo »
"OpenStreetMap"OpenStreetMap »
A StringTemplate or other template object may also be supplied to the GeoServer option, in which case the template is called with zoom, decimal latitude, and decimal longitude provided as the first, second, and third slots respectively.
If a template object is supplied to the GeoServer option, any setting for the GeoBackground option is ignored.
The following settings are supported for the GeoBackground option:
Automaticthe default map type
"Satellite"satellite imagery
"StreetMap"street map data
"Terrain"basic street map data with shaded topography and elevation
With GeoBackgroundAutomatic, the first available map type for the specified GeoServer is used, with "StreetMap" taking precedence.
Some mapping services do not support both map types.
With GeoServer → "GoogleEarth", the GeoZoomLevel option is interpreted as camera altitude in meters. For other settings of GeoServer, it is generally equivalent to GeoZoomLevel as used with functions like GeoGraphics and GeoImage.

Examples

Basic Examples (3) 

Open your current location in Google Maps:

In[1]:=
ResourceFunction["OpenWebMap"][Here]

See the URL opened by the previous example:

In[2]:=
ResourceFunction["OpenWebMap"][Here, "URL"]
Out[2]=

Open satellite imagery:

In[3]:=
ResourceFunction["OpenWebMap"][GeoPosition[{48.86, 2.34}], GeoBackground -> "Satellite"]

Scope (2) 

Use the geographical position of an entity:

In[4]:=
ResourceFunction["OpenWebMap"][
 Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}], "URL"]
Out[4]=

Use different mapping services:

In[5]:=
ResourceFunction["OpenWebMap"][Here, "URL", GeoServer -> #] & /@ {"Bing", "Google", "HERE", "OpenStreetMap"}
Out[5]=

Options (3) 

GeoServer (1) 

Specify a custom GeoServer with a StringTemplate:

In[6]:=
ResourceFunction["OpenWebMap"][Here, "URL", GeoServer -> StringTemplate[
   "https://mymapsite.com/map?zoom=`1`&lat=`2`&lon=`3`"]]
Out[6]=

GeoZoomLevel (2) 

With GeoServer → "GoogleEarth", GeoZoomLevel is interpreted as camera altitude in meters:

In[7]:=
ResourceFunction["OpenWebMap"][Here, "URL", GeoServer -> "GoogleEarth"]
Out[7]=

With other mapping services, values for GeoZoomLevel are approximately equivalent to those used with functions like GeoGraphics and GeoImage:

In[8]:=
position = Entity["City", {"Madrid", "Madrid", "Spain"}]["Position"]
Out[8]=
In[9]:=
ResourceFunction["ImageSplitCompare"][
 WebImage[
  First@ResourceFunction["OpenWebMap"][position, "URL", GeoServer -> "Bing", GeoZoomLevel -> 13]],
 GeoImage[position, "StreetMap", GeoZoomLevel -> 13],
 Automatic, "Fit"
 ]
Out[9]=

Properties and Relations (1) 

With GeoServer"GoogleEarth", if a GeoPosition object containing height data is supplied, the height value is used as the setting for GeoZoomLevel:

In[10]:=
ResourceFunction["OpenWebMap"][
 GeoPosition[{48.85833, 2.29444, 700}], "URL", GeoServer -> "GoogleEarth"]
Out[10]=

Possible Issues (2) 

Some mapping services don’t support all map types:

In[11]:=
ResourceFunction["OpenWebMap"][Here, "URL", GeoServer -> "OpenStreetMap", GeoBackground -> "Satellite"]
Out[11]=

If a GeoPosition containing multiple positions is supplied to OpenWebMap, the mean of all contained positions is taken:

In[12]:=
position = GeoPosition[
  DeleteMissing@
   EntityValue[
    EntityClass["Country", "Countries"][
     EntityProperty["Country", "CapitalCity"]], "Position"]]
Out[12]=
In[13]:=
ResourceFunction["OpenWebMap"][position, "URL"]
Out[13]=
In[14]:=
% === ResourceFunction["OpenWebMap"][
  Mean@position["LatitudeLongitude"], "URL"]
Out[14]=

Neat Examples (3) 

Use WebImage to retrieve a screenshot of a mapping service:

In[15]:=
WebImage[First@
  ResourceFunction["OpenWebMap"][
   Entity["Island", "PalmJumeirah::r87sm"], "URL", GeoServer -> "Bing", GeoBackground -> "Satellite", GeoZoomLevel -> 13]]
Out[15]=

Open the current view of the International Space Station in Google Earth, with the altitude of the camera set to that of the station:

In[16]:=
issPosition = Entity["Satellite", "25544"][EntityProperty["Satellite", "Position"]]
Out[16]=
In[17]:=
ResourceFunction["OpenWebMap"][issPosition, "URL", GeoServer -> "GoogleEarth"]
Out[17]=

Change the default GeoServer to suit your personal corporate loyalties (or lack of the same):

In[18]:=
SetOptions[ResourceFunction["OpenWebMap"], GeoServer -> "OpenStreetMap"]
Out[18]=
In[19]:=
ResourceFunction["OpenWebMap"][
 Entity["City", {"BuenosAires", "BuenosAires", "Argentina"}], "URL"]
Out[19]=

Publisher

Jesse Friedman

Version History

  • 2.0.0 – 11 October 2019
  • 1.0.0 – 03 October 2019

Related Resources

Author Notes

URL templates for several other mapping services are available at the source for Wikipedia’s GeoHack tool.

License Information