2

On my _entry page, I'm trying to get the SmartMap plugin to generate a dynamic map, but it gets stuck on 'Loading Map'

Using this as the code:

{{ craft.smartMap.map(entry.theEventAddress) }}

and the console tells me:

Uncaught SyntaxError: Unexpected token ,

The documentation is a bit vague on this, and it doesn't really tell you how to fix JavaScript errors. Also, I have API keys in the settings.

EDIT

Here's the output as requested. Using the latest version of the plugin. (2.3.1)

<script type="text/javascript">
/*<![CDATA[*/
if (logSmartMap) {console.log("[smartmap-mapcanvas-1] Drawing map...");}
smartMap.createMap("smartmap-mapcanvas-1", {"center":smartMap.coords(-48.876667,-123.393333),"scrollwheel":false});
if (logSmartMap) {console.log("[smartmap-mapcanvas-1.2497.theEventAddress] Drawing marker...");}
smartMap.createMarker("smartmap-mapcanvas-1.2497.theEventAddress", {"mapId":"smartmap-mapcanvas-1","map":smartMap.map["smartmap-mapcanvas-1"],"position":smartMap.coords(,)});
if (logSmartMap) {console.log("[smartmap-mapcanvas-1] Fitting bounds...");}
smartMap.fitBounds("smartmap-mapcanvas-1");
/*]]>*/
</script>

This is the problem line:

smartMap.createMarker("smartmap-mapcanvas-1.2497.theEventAddress", {"mapId":"smartmap-mapcanvas-1","map":smartMap.map["smartmap-mapcanvas-1"],"position":smartMap.coords(,)});
  • Can you post a snippet of the generated source code, specifically where the console error is being thrown? Also, are you running the latest version of Smart Map (v2.3.1)? – Lindsey D Jan 11 '16 at 0:27
  • I'm using 2.3.1 -- See post edit. – Dustin C Jan 11 '16 at 1:26
  • Interesting, thanks. The JS error is being thrown by this specific chunk of code: "position":smartMap.coords(,)... Looks like a bug. For your entry with the ID of 2497, does theEventAddress have coordinates? Or are the latitude & longitude fields blank? – Lindsey D Jan 11 '16 at 2:50
  • They are blank. I didn't include them in the address entry field because I can't count on the client to enter the coords for the location. That's why I specifically bought this plugin. – Dustin C Jan 11 '16 at 4:20
  • It's possible for an address to have multiple possible matches. The address selection modal ensures that the user is selecting the correct address, not just the first match. – Lindsey D Jan 11 '16 at 4:50
2

There are actually two problems happening here...

(1) For a location to appear on a map, it's critical for the latitude & longitude to be filled in. Within the UX of the Address field, this can happen a few different ways... as you mentioned, clicking "Select Address" is one of the main ways of doing so. Additionally, the address selection modal will be automatically triggered when you tab between fields.

(2) There is apparently a small bug in Smart Map, which I'll go ahead and patch. If a location is lacking coordinates, the JS shouldn't attempt to render that marker. It should just be omitted from the map instead.

Hope that helps. I'll release a patch shortly.


UPDATE:

I just pushed out Smart Map v2.3.2, which fixes the bug. Instead of triggering a JS error, the marker will simply be skipped. In that case, the JS console will output the following message:

Unable to draw marker, invalid coordinates.

Hope that helps! For anyone who may need further support on this issue, feel free to email support@doublesecretagency.com.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.