Solved

Javascript executes correctly in JSFiddle but not in Acumatica

  • 26 August 2023
  • 5 replies
  • 102 views

Badge +11

This question is an extension of this one.

I have changed the second script to be as follows:

<script>
var map;
async function initMap() {
const center = { lat: 40.75, lng: -77 };
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
const { Geocoder } = await google.maps.importLibrary("geocoding");

/* the map */
map = new Map(document.getElementById("map"), {
zoom: 7.8,
center: center,
mapId: "DEMO_MAP_ID",
});

/* get addresses from Acumatica field */
/*var addressesToPlot = px_alls["cstAddressesToPlot"].getValue();*/
var addressesToPlot = "Robisonia, PA; Mechanicsburg, PA; Philadelphia, PA";
var addresses = addressesToPlot.split(';');

/* encode addresses as lat/lng */
const geocoder = new Geocoder();
for (var i=0; i<addresses.length; i++)
{
geocoder.geocode({ 'address': addresses[i] }, (results, status) => {
if (status == google.maps.GeocoderStatus.OK) {
const marker = new AdvancedMarkerElement({
map: map,
position: results[0].geometry.location,
title: addresses[i],
});
}
});
}
}
initMap();
</script>

The page loads the map correctly, but the markers are not plotted on the map. However, the same code runs just fine in JSFiddle: (try it)


Could someone with more experience in JavaScript explain why that is?

@zfebert56 

icon

Best answer by Zoltan Febert 28 August 2023, 17:29

View original

5 replies

Userlevel 6
Badge +3

Can you see any errors in the JavaScript console?

Badge +11

Can you see any errors in the JavaScript console?

This was a fantastic idea I had not thought of, since, as previously mentioned, I have very little experience with JavaScript.

I’m genuinely embarrassed to say that the problem was that I had previously disabled the geocoding API in the Google API Console 🙈

Userlevel 7
Badge

Thank you for sharing your solution with the community @darylbowman!

@darylbowman - any chance you can explain this piece? 

var addressesToPlot = px_alls["cstAddressesToPlot"].getValue();

Where is cstAddressesToPlot defined/coming from?

Userlevel 6
Badge +3

@bguzman43 That is the control ID on the screen.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved