Show Two Entities In Bing Maps In Canvas App

Introduction


This is the second article about using Bing maps in the Canvas app. In the first article we discussed about how we can show event organizer data in the gallery control and render them in the Bing maps. In this article we are going to show events as well as event organization details in Bing maps.
Details
 
In the last app we rendered event organizations in the Bing maps but now let’s say we also want to show event location with event organizations. To show event location over a map we need to add geo coordinates to event entity (Latitude and Longitude), so let’s modify our event entity and add some other address field and latitude and longitude like below:
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Once we have added this field we need to add some logic to get geo coordinates based on the address details. We can create a simple Power Automate to get these details using the following steps.
 
Step 1
 
Navigate to Power Automate from your subscriptions, click on Create to create automated Flow.

Step 2
 
Select Common Data Service connector and select the below trigger.
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Step 3
 
Configuration step for your flow
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Step 4
 
Search for Bing maps connector and select get location by address action, we need to pass address details to get latitude and longitude
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Step 5
 
Next add steps to update these details to event entity like following
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Step 6
 
Save your changes and test your flow to make sure it's getting details after event record is created.
 
Now we have geocoordinates of the event location, let’s change our canvas app.
 
Open canvas app in edit mode and drag Reload icon and place on the title bar like below
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Now we need to add the following code in OnSelect event of the icon.
  1. //Create new collection of event and event organizer  
  2. UpdateContext(  
  3.     {  
  4.         eventwitheventorgCol: Concatenate(  
  5.             eventorganizersCol,  
  6.             "&pp=",  
  7.             Text(ModelDrivenFormIntegration.Item.Latitude),  
  8.             ",",  
  9.             Text(ModelDrivenFormIntegration.Item.Longitude),  
  10.             ";" & "129" & ";"  
  11.         )  
  12.     }  
  13. );  
  14. //create a variable mapURL to set it to image control  
  15. Set(  
  16.     mapURL,  
  17.     "https://dev.virtualearth.net/REST/v1/Imagery/Map/Road?mapSize=650,400" & eventwitheventorgCol & "&zoomlevel=14" & "&key=BINGMapKey"  
  18. );  
  19. //refresh form  
  20. ModelDrivenFormIntegration.RefreshForm(false);  
In the first express we are combining our existing eventorganizersCol with we created in our part1 with the event details. To get event details we are using ModelDrivenFormIntegration control which will provide us details of the current record, we can consider this control just like executioncontext which we use in entity forms to get context information. You can get more details about this control from here. To get current record fields we can simply use the  following option of this control.
 
ModelDrivenFormIntegration.Item.<Field Display Name>
 
We are concatenating event organization details with event and using 129 (push pin icon style) to show event location. Next we are creating a variable to hold Bing maps static url which we will be using under the image property of image control.
  1. Set(  
  2. mapURL,  
  3. “https://dev.virtualearth.net/REST/v1/Imagery/Map/Road?mapSize=650,400″ & eventwitheventorgCol & “&zoomlevel=14″ & “&key=Bingmap key”  
  4. );  
We can change our old code where we are showing event organization similarly to url for the event organizers.
 
Now we set this variable under image control.
 
Canvas App With Bing Maps In Dynamics 365 CE
 
Finally we save and publish our app. Now we will create event record and we will be able to see map like below,
 
Canvas App With Bing Maps In Dynamics 365 CE
 
And if we want to see Event location with event organizations we can click on the Reload icon and it will show both details like below,
 
Canvas App With Bing Maps In Dynamics 365 CE
 

Summary


This is how we can get geocoordinates using simple Power Automate and show two entity details in the Bing maps.
 
We will be doing some more changes to our demo app so stay tuned!.
 
I hope it will help someone!

Keep learning, Keep sharing!!


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.