{"id":157,"date":"2017-10-18T08:08:56","date_gmt":"2017-10-18T15:08:56","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/image-control-static-maps-api\/"},"modified":"2025-06-11T08:11:28","modified_gmt":"2025-06-11T15:11:28","slug":"image-control-static-maps-api","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/image-control-static-maps-api\/","title":{"rendered":"Displaying a Map using an Image Control in PowerApps and Bing Maps or Google Maps API"},"content":{"rendered":"
\u00a0<\/p>\n
There have been a lot of requests from the community about the ability to display a map in PowerApps. While we don\u2019t yet have a Maps Control in PowerApps, we can use the Image Control<\/a> to display maps – thankfully to Bing Maps<\/strong><\/a> OR Google Maps<\/strong><\/a> via the Bing Maps Imagery API<\/strong><\/a> & Google Static Maps API<\/strong><\/a> respectively.<\/p>\n \u00a0<\/p>\n Here are the scenarios that we will build today using the Image Control:<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Get the Bing Maps API Key by visiting this URL<\/a> OR the Google Static Maps API Key by visiting this URL<\/a>. Note down the Key for use later in the tutorial.<\/p>\n In the PowerApps Studio or Web, Create a New <\/strong>Blank app (pick either Phone or Tablet layout as per your need).<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n We\u2019ll first create a Configuration Screen to store some information which can be used by other screens in the app. Rename<\/strong> the Screen1<\/strong> to ConfigurationScreen<\/strong> from the Tree view on the left side.<\/p>\n \u00a0<\/p>\n Rename<\/strong> the control from TextInput1<\/strong> to txtBingMapsKey <\/strong>(If you want to use the Bing Maps API) or txtGoogleMapsKey<\/strong> (if you want to use Google Maps API). Change<\/strong> HintText<\/strong> to \u201cEnter Maps Key here\u201d and the Default <\/strong>to the ACTUAL KEY value from the Bing Maps or the Google Maps site from the first step of this tutorial.<\/p>\n \u00a0<\/p>\n Insert <\/strong>another Text input <\/strong>control from the Insert <\/strong>tab > Text<\/strong> > Text input. Rename <\/strong>this control to txtImageWidth, <\/strong>change Hint Text to \u201cEnter Maps Image Width here\u201d, change Default <\/strong>to \u201c600<\/strong>\u201d (if phone layout) or \u201c1200<\/strong>\u201d (if tablet layout), change Format<\/strong> to Number <\/strong>from the Properties pane on the right.<\/p>\n \u00a0<\/p>\n Copy <\/strong>the txtImageWidth (CTRL + C) and Paste (CTRL + V) in the same screen to create a copy. Rename <\/strong>the control to txtImageHeight, <\/strong>change the Hint Text<\/strong> to \u201cEnter Maps Image Height here\u201d, change Default<\/strong> to \u201c300<\/strong>\u201d (for phone layout) and \u201c600<\/strong>\u201d (for tablet layout).<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Insert <\/strong>> New Screen <\/strong>> Blank layout.<\/strong> \u00a0<\/p>\n \u00a0<\/p>\n Rename <\/strong>the control from Image1 to imgMapControl. <\/strong>Set the Width <\/strong>to txtImageWidth <\/strong>and Height <\/strong>to txtImageHeight. <\/strong><\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Let\u2019s insert a Text input control to enter the location or address for the map: Insert <\/strong>Tab > Text <\/strong>> Text input. Rename <\/strong>the control to txtLocation. <\/strong>Move it to a location in the screen where appropriate.<\/p>\n Change Hint Text <\/strong>as \u201cEnter a location or address\u201d and keep Default <\/strong>as an empty string \u201c\u201d or your favorite location \u2013 for e.g. Times Square, New York, Seattle etc…<\/p>\n \u00a0<\/p>\n For rendering the Map, use the following formula in the Image <\/strong>property of the imgMapControl <\/strong>:<\/p>\n \u00a0<\/p>\n For Bing Maps Use:<\/strong><\/p>\n Bing Maps:<\/strong> Refer to the Get a Static Map<\/strong><\/a> article for examples and other parameters.<\/p>\n \u00a0<\/p>\n For Google Maps Use:<\/strong><\/p>\n Google Maps: <\/strong>Refer to examples and parameters in the Google Static Maps Developer Guide<\/strong><\/a>.<\/p>\n \u00a0<\/p>\n Here are the screenshots for the Location: Space Needle, Seattle using Bing Maps:<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n And here is the same location using Google Maps (note the size is restricted to 640×640 in Google Maps, as I am using a Free version of the API):<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Changing ImagerySets (Bing Maps) and Map Types (Google Maps):<\/p>\n \u00a0<\/p>\n Bing Maps<\/strong> supports multiple imagerySets. Lets add a dropdown to see the effect of changing these imagerySets.<\/p>\n Insert<\/strong> > Controls <\/strong>> Dropdown <\/strong>to add a dropdown. Rename <\/strong>the control to drpBingImagerySets<\/strong>. Set the Items <\/strong>property to the following:<\/p>\n \u00a0<\/p>\n Change the formula in the Image <\/strong>property of the imgMapControl <\/strong>to include the imagerySet option :<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Insert<\/strong> > Controls <\/strong>> Dropdown <\/strong>to add a dropdown. Rename <\/strong>the control to drpGoogleMaptypes<\/strong>. Set the Items <\/strong>property to the following:<\/p>\n \u00a0<\/p>\n Change the formula in the Image <\/strong>property of the imgMapControl <\/strong>to include the maptype option :<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n These Map APIs are pretty powerful and I am sure, you will be tempted to try out other options available for customization. For now let\u2019s move on to the next scenario:<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n PowerApps provides native access to Device Signals<\/a> such as Location (GPS), Acceleration, Compass, etc. Let\u2019s use the Location<\/a> signal to show the current location on a map.<\/p>\n For that, we shall use the same txtLocation Text input to display the GPS coordinates if we select a Toggle to use GPS Location.<\/p>\n Insert > Controls > Toggle<\/strong> to insert a Toggle<\/strong> control on the screen. Rename<\/strong> it to tglGPSLocation<\/strong>.<\/p>\n \u00a0<\/p>\n Insert > Label <\/strong>to insert a Label <\/strong>control on the screen. Move it next to the Toggle and rename<\/strong> it to lblGPSLocation<\/strong>. Change the Text to \u201cUse GPS Location:\u201d.<\/p>\n Change the Default<\/strong> of the txtLocation<\/strong> Input text to this formula:<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n For Bing Maps<\/strong>, change the formula in the Image <\/strong>property of the imgMapControl <\/strong>to include the centerpoint & pushpin options (Note we have to add the zoomLevel as well):<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n For Google Maps<\/strong>, change the formula in the Image <\/strong>property of the imgMapControl <\/strong>to include the center & markers options (Note we have to add the zoomLevel as well):<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Moving the final scenario, lets add a Slider <\/strong>control to control the Zoom level. Insert > Controls > Slider<\/strong>. Rename <\/strong>the Slider1<\/strong> to slZoom<\/strong>. Change Default <\/strong>to 15<\/strong>, Min <\/strong>to 1 <\/strong>& Max <\/strong>to 21<\/strong>.<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Add a Label <\/strong>next to the slider to denote the zoom level. Insert > Label<\/strong>. Rename <\/strong>the Label to lbZoom<\/strong>. Change Text <\/strong>to : “Zoom (1-21):”.<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n For Bing Maps<\/strong>, change the formula in the Image <\/strong>property of the imgMapControl <\/strong>to include the\u00a0 zoomLevel from the slider.<\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n For Google Maps<\/strong>, change the formula in the Image <\/strong>property of the imgMapControl <\/strong>to include the\u00a0 zoomLevel from the slider.<\/p>\n \u00a0<\/p>\n Lastly, lets add the navigation step when clicked on the image to open up the respective web page or app.<\/p>\n \u00a0<\/p>\n For Bing Maps<\/strong>,\u00a0 add the following Formula in the OnSelect <\/strong>for the imgMapControl:<\/strong><\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Refer to this article for details: https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/launch-resume\/launch-maps-app<\/a><\/p>\n \u00a0<\/p>\n For Google Maps<\/strong>, add the following Formula in the OnSelect <\/strong>for the imgMapControl:<\/strong><\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Refer to this article for details: https:\/\/developers.google.com\/maps\/documentation\/urls\/guide<\/a><\/p>\n \u00a0<\/p>\n \u00a0<\/p>\nMap scenarios<\/h2>\n
\n
<\/h3>\n
Preparation<\/h3>\n
<\/p>\nAdd a Configuration Screen<\/h4>\n

\nInsert<\/strong> a Text input <\/strong>control from the Insert <\/strong>Tab > Text <\/strong>> Text input <\/strong>
\n
<\/p>\n
<\/p>\nAdd the Main Screen<\/h4>\n
\nRename<\/strong> the Screen2<\/strong> to MainScreen.<\/strong>
\nMove <\/strong>the MainScreen <\/strong>Up by clicking on the Move Up <\/strong>icon in the context menu<\/p>\n
\nInsert <\/strong>> Media<\/strong> > Image <\/strong>control to add a new Image to the screen.<\/p>\n
<\/p>\nScenario 1: Display a map for a given named location or address<\/h3>\n
\"https:\/\/dev.virtualearth.net\/REST\/V1\/Imagery\/Map\/Road\/\" & EncodeUrl(txtLocation.Text) & \"?mapSize=\" & txtImageWidth & \",\" & txtImageHeight & \"&key=\"&txtBingMapsKey.Text<\/pre>\n
\"https:\/\/maps.googleapis.com\/maps\/api\/staticmap?center=\" & EncodeUrl(txtLocation.Text) & \"&size=\" & txtImageWidth & \"x\" & txtImageHeight & \"&key=\"&txtGoogleMapsKey.Text<\/pre>\n
<\/p>\n
<\/p>\nPlaying with some of the options<\/h3>\n
[\"Road\",\"Aerial\", \"AerialWithLabels\", \"AerialWithLabelsOnDemand\", \"CanvasDark\", \"CanvasLight\", \"CanvasGray\"]<\/pre>\n
\"https:\/\/dev.virtualearth.net\/REST\/V1\/Imagery\/Map\/\" & drpBingImagerySets.Selected.Value & \"\/\" & EncodeUrl(txtLocation.Text) & \"?mapSize=\" & txtImageWidth & \",\" & txtImageHeight & \"&key=\"&txtBingMapsKey.Text<\/pre>\n

\nGoogle Maps <\/strong>supports four types of maptypes. Lets add a dropdown to see the effect of changing these types.<\/p>\n[\"roadmap\",\"terrain\", \"satellite\", \"hybrid\"]<\/pre>\n
\"https:\/\/maps.googleapis.com\/maps\/api\/staticmap?center=\" & EncodeUrl(txtLocation.Text) & \"&&size=\" & txtImageWidth & \"x\" & txtImageHeight & \"&maptype=\" & drpGoogleMaptypes.Selected.Value & \"&key=\"&txtGoogleMapsKey.Text<\/pre>\n
<\/p>\nScenario 2: Display a map for the current GPS location of the device<\/h3>\n
<\/p>\n
<\/p>\nIf(tglGPSLocation.Value, Location.Latitude & \",\"& Location.Longitude ,\"\")<\/pre>\n
\"https:\/\/dev.virtualearth.net\/REST\/V1\/Imagery\/Map\/\"&drpBingImagerySets.Selected.Value&\"\/\" & EncodeUrl(txtLocation.Text) & \"\/15?mapSize=\" & txtImageWidth & \",\" & txtImageHeight & \"&pp=\" & txtLocation.Text & \";21;I+am+here&key=\"&txtBingMapsKey.Text<\/pre>\n
<\/p>\n\"https:\/\/maps.googleapis.com\/maps\/api\/staticmap?center=\" & EncodeUrl(txtLocation.Text) & \"&zoom=15&size=\" & txtImageWidth & \"x\" & txtImageHeight & \"&maptype=\" & drpGoogleMaptypes.Selected.Value & \"&markers=color:blue%7Clabel:M%7C\"& EncodeUrl(txtLocation.Text)& \"&key=\"&txtGoogleMapsKey.Text<\/pre>\n
<\/p>\nScenario 3: Zoom In \/ Zoom Out using a Slider<\/h3>\n
<\/p>\n
<\/p>\n\"https:\/\/dev.virtualearth.net\/REST\/V1\/Imagery\/Map\/\"&drpBingImagerySets.Selected.Value&\"\/\" & EncodeUrl(txtLocation.Text) & \"\/\"& slZoom.Value &\"?mapSize=\" & txtImageWidth & \",\" & txtImageHeight & \"&pp=\" & txtLocation.Text & \";21;I+am+here&key=\"&txtBingMapsKey.Text<\/pre>\n
\"https:\/\/maps.googleapis.com\/maps\/api\/staticmap?center=\" & EncodeUrl(txtLocation.Text) & \"&zoom=\"& slZoom.Value & \"&size=\" & txtImageWidth & \"x\" & txtImageHeight & \"&maptype=\" & drpGoogleMaptypes.Selected.Value & \"&markers=color:blue%7Clabel:M%7C\"& EncodeUrl(txtLocation.Text)& \"&key=\"&txtGoogleMapsKey.Text<\/pre>\n
<\/pre>\n
Scenario 4: Navigate to the Maps app or Web Page when clicked<\/h3>\n
If(tglGPSLocation.Value, Launch(\"bingmaps:?cp=\" & EncodeUrl(Substitute(txtLocation.Text,\",\",\"~\"))&\"&lvl=\"&slZoom.Value), Launch(\"bingmaps:?q=\" & EncodeUrl(txtLocation.Text)&\"&lvl=\"&slZoom.Value))<\/pre>\n
Launch(\"http:\/\/maps.google.com\/?q=\"&EncodeUrl(txtLocation.Text))<\/pre>\n
Download the Sample App<\/h3>\n