Home Forums Front-end Issues Google Map not inserting marker


Google Map not inserting marker

  • I’m having a strange issue when trying to display a Google Map on a post in the front end and I hope someone can suggest a solution. I’m using the code provided on the Google Map field documentation field. I’d include it here but it’s literally the same code.

    What’s happening is that the map is being generated but the marker is not being inserted. It’s almost like it’s skipping over the add_marker function entirely. In fact I put a JS alert within each of the functions as a test and the only one that didn’t show is the one in the add_marker function but everything within that function seems fine.

    The field data is coming through as I can see it using print_r and also within the JS in the inspector in Chrome.

    If I comment out the function call to center_map function in the render_map function, the map shows the right area but there is no marker. If I leave in the center_map function the map centers somewhere in the Pacific Ocean (presumably because there is no Marker for the map to center itself to.)

    I’ve gone through the code over and over and can’t see any issues. I’m no JS master but I have a pretty good understanding of it.

    All the Google Map related scripts seem to be loading fine (looking under Network in the Inspector). Also, I used the exact same code in another project and it’s working fine. There are no other Google Map plugins running and I tried disabling all my plugins except ACF with no change.

    Can anyone suggest anything I should look into?


  • As usual, 10 minutes after posting the question I found the issue.

    I’m embarrassed to admit that in the first line of the main function where $markers is defined I had put in the selector of the .acf-map before .marker, so it was trying to look within $el (which is itself ‘.acf-map’) for another .acf-map and within that, .marker.

    A stupid mistake, but hopefully someone, somewhere will find this useful!

  • I ahve the same issue, my map is working in the backend – when I type address I can see the marker, but in front end no marker. I haven’t changed anything in the code from documentation, apart my field name in
    $location = get_field('map');
    What else am I missing?
    You solution doesn’t mean much to me, have you changed anything in the JS file?

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Google Map not inserting marker’ is closed to new replies.