Skip to main content
Solved

Has anyone embedded Google Maps in an Acumatica aspx page?


darylbowman
Captain II
Forum|alt.badge.img+13

I am wondering if it is possible to display a Google Maps map generated from the Maps JavaScript API in an ASPX page.

Does anyone have experience with this or something similar?

Best answer by Zoltan Febert

OK, let’s do it with JavaScript.

Add these three PXLiteral to your page. The first loads Google API, the second displays the map, and the third declares the div for the map.
I got the scripts from here: https://developers.google.com/maps/documentation/javascript/adding-a-google-map#javascript

I do not have an API key, so I used the Beta key from the documentation. It didn’t display the map properly, but I saw the scripts were running. 

Once you replace the demo scripts with your working ones, you should do it in the customization editor, and PXLiteral control will encode them properly. Make sure there is no line comment in your script, because PXLiteral converts the multi line script into a one line script, and half of your script will be commented out. 

      <px:PXLiteral Enabled="True" runat="server" ID="s1" Text="&lt;!-- prettier-ignore -->     &lt;script>(g=>{var h,a,k,p=&quot;The Google Maps JavaScript API&quot;,c=&quot;google&quot;,l=&quot;importLibrary&quot;,q=&quot;__ib__&quot;,m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement(&quot;script&quot;));e.set(&quot;libraries&quot;,[...r]+&quot;&quot;);for(k in g)e.set(k.replace(/[A-Z]/g,t=>&quot;_&quot;+t[0].toLowerCase()),g[k]);e.set(&quot;callback&quot;,c+&quot;.maps.&quot;+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+&quot; could not load.&quot;));a.nonce=m.querySelector(&quot;script[nonce]&quot;)?.nonce||&quot;&quot;;m.head.append(a)}));d[l]?console.warn(p+&quot; only loads once. Ignoring:&quot;,g):d[l]=(f,...n)=>r.add(f)&amp;&amp;u().then(()=>d[l](f,...n))})         ({key: &quot;AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&quot;, v: &quot;beta&quot;});&lt;/script>" ></px:PXLiteral>
      <px:PXLiteral Enabled="True" runat="server" ID="s2" Text="&lt;script > let map; function retek() {}; async function initMap() {    const position = { lat: -25.344, lng: 131.031 };        const { Map } = await google.maps.importLibrary(&quot;maps&quot;);   const { AdvancedMarkerElement } = await google.maps.importLibrary(&quot;marker&quot;);      map = new Map(document.getElementById(&quot;map&quot;), {     zoom: 4,     center: position,     mapId: &quot;DEMO_MAP_ID&quot;,   });    const marker = new AdvancedMarkerElement({     map: map,     position: position,     title: &quot;Uluru&quot;,   }); }  initMap();   &lt;/script>" ></px:PXLiteral>
      <px:PXLiteral Text="&lt;div id=&quot;map&quot; style=&quot;height:400px; width:400px&quot;>&lt;/div>" runat="server" ID="s3" ></px:PXLiteral>

 

View original
Did this topic help you find an answer to your question?

6 replies

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3

Hi @darylbowman,

If JavaScript is not necessary, you can use a simple Label and embedded HTML map like this:

<px:PXLabel Height="400" Text="&lt;iframe src=&quot;https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3094853.40138902!2d-76.81555214851113!3d40.755035!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89c259ace01f6307%3A0x6a70a25994abe692!2sNet%20at%20Work%20%7C%20Managed%20IT%20Services%20%26%20Support%20(MSP)%20New%20York%20%7C%20Technology%2C%20Software%20%26%20Business%20Consulting!5e0!3m2!1sen!2sca!4v1692987544368!5m2!1sen!2sca&quot; width=&quot;600&quot; height=&quot;450&quot; style=&quot;border:0;&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; referrerpolicy=&quot;no-referrer-when-downgrade&quot;>&lt;/iframe>" runat="server" ID="GooglePanel" ></px:PXLabel>

 


darylbowman
Captain II
Forum|alt.badge.img+13
  • Author
  • 1749 replies
  • August 25, 2023
zfebert56 wrote:

If JavaScript is not necessary, you can use a simple Label and embedded HTML map like this:

Interesting. Unfortunately, I would like to use the JavaScript API to plot points on the map.


Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • 176 replies
  • Answer
  • August 26, 2023

OK, let’s do it with JavaScript.

Add these three PXLiteral to your page. The first loads Google API, the second displays the map, and the third declares the div for the map.
I got the scripts from here: https://developers.google.com/maps/documentation/javascript/adding-a-google-map#javascript

I do not have an API key, so I used the Beta key from the documentation. It didn’t display the map properly, but I saw the scripts were running. 

Once you replace the demo scripts with your working ones, you should do it in the customization editor, and PXLiteral control will encode them properly. Make sure there is no line comment in your script, because PXLiteral converts the multi line script into a one line script, and half of your script will be commented out. 

      <px:PXLiteral Enabled="True" runat="server" ID="s1" Text="&lt;!-- prettier-ignore -->     &lt;script>(g=>{var h,a,k,p=&quot;The Google Maps JavaScript API&quot;,c=&quot;google&quot;,l=&quot;importLibrary&quot;,q=&quot;__ib__&quot;,m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement(&quot;script&quot;));e.set(&quot;libraries&quot;,[...r]+&quot;&quot;);for(k in g)e.set(k.replace(/[A-Z]/g,t=>&quot;_&quot;+t[0].toLowerCase()),g[k]);e.set(&quot;callback&quot;,c+&quot;.maps.&quot;+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+&quot; could not load.&quot;));a.nonce=m.querySelector(&quot;script[nonce]&quot;)?.nonce||&quot;&quot;;m.head.append(a)}));d[l]?console.warn(p+&quot; only loads once. Ignoring:&quot;,g):d[l]=(f,...n)=>r.add(f)&amp;&amp;u().then(()=>d[l](f,...n))})         ({key: &quot;AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&quot;, v: &quot;beta&quot;});&lt;/script>" ></px:PXLiteral>
      <px:PXLiteral Enabled="True" runat="server" ID="s2" Text="&lt;script > let map; function retek() {}; async function initMap() {    const position = { lat: -25.344, lng: 131.031 };        const { Map } = await google.maps.importLibrary(&quot;maps&quot;);   const { AdvancedMarkerElement } = await google.maps.importLibrary(&quot;marker&quot;);      map = new Map(document.getElementById(&quot;map&quot;), {     zoom: 4,     center: position,     mapId: &quot;DEMO_MAP_ID&quot;,   });    const marker = new AdvancedMarkerElement({     map: map,     position: position,     title: &quot;Uluru&quot;,   }); }  initMap();   &lt;/script>" ></px:PXLiteral>
      <px:PXLiteral Text="&lt;div id=&quot;map&quot; style=&quot;height:400px; width:400px&quot;>&lt;/div>" runat="server" ID="s3" ></px:PXLiteral>

 


darylbowman
Captain II
Forum|alt.badge.img+13
  • Author
  • 1749 replies
  • August 26, 2023

Thank you! I was trying pieces of this but couldn’t get far enough to have a basic working model. This is surprisingly simple. The real API key did make the difference.

I appreciate the time you spent. Thanks again!


@darylbowman Is there a maximum number of records you can plot on the google maps API?


darylbowman
Captain II
Forum|alt.badge.img+13
  • Author
  • 1749 replies
  • December 2, 2024

Not according to Google. However, there may be limitations to the how many points can be passed from the Acumatica backend to the JavaScript frontend.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings