Support

Account

Home Forums Bug Reports Google Map location marker snapping to nearest road

Solving

Google Map location marker snapping to nearest road

  • Since updating to ACF Pro Version 5.8.6, the backend map location marker cannot be manually dragged into place. Instead it snaps to the nearest road / address.

    In my use case we’ve been marking places of interest in the countryside, but the location marker is then snapping to the nearest road.

  • We’re seeing the same issue where our custom ‘countryside’ pins can no longer be placed as such and the pin will snap to the nearest road or point of interest.

    We have come up with a fix for it, but it would be ideal if ACF could acknowledge if this is indeed a bug or a feature we need to now workaround?

    • Theo LG

    • November 6, 2019 at 7:35 pm

    We have the same issue, we create maps with pointers that need to be geolocated precisely.

    Is there an option to disable this feature ?

    @adammontague : Can you share your fix?

    Thanks,

  • Load the following script in your admin.

    var hm_googlemap = null;
    
    if (eval("typeof acf") != undefined) {
      console.log('ACF IS HERE!');  
      
      acf.addAction('google_map_init', function(map, marker, field) {
        hm_googlemap = map;
    
        //Override the searchPosition function on the 
        //map ACF Field which normally does a geocode search
        field.__proto__.searchPosition = function(lat, lng) {	      
          var zoom = (hm_googlemap !== null) ? hm_googlemap.zoom : 15;
          var val = {
            address: "Custom Location: (" + lat + ", " + lng + ")",
            lat: lat,
            lng: lng,
            zoom: zoom,
            country: "", 
            country_short: "", 
            place_id: "",
            post_code: "", 
            state: "", 
            street_name: "", 
            street_name_short: "",
          };
          
    //console.log(val);
    	  this.val(val);				
        };    
      });  
    }
    • Theo LG

    • November 7, 2019 at 12:13 am

    Works like a charm, Thanks,

  • Had the same problem and the script above fixed it, but this does feel like a bug introduced by the latest update.

  • Thank you @adammontague, this solves the problem, though it would be good to know when the bug will be patched. I presume this is a bug rather than a feature because of the many ways in which people use the Google Maps field. I’d be surprised if the functionality was deliberately limited without consultation.

    • Vitamin

    • December 7, 2019 at 3:19 am
    This reply has been marked as private.
  • Hi there, same issue here. Is that a bug of a feature?

    • Theo LG

    • January 14, 2020 at 2:12 am

    It seems to be related to a new feature from 5.8.6 “New : The Google Map field saves more location data in version 5.8.6!”
    https://www.advancedcustomfields.com/resources/google-map/

    • mkalina

    • February 25, 2020 at 3:36 am

    Oh my, this feature cost me headaches. The script works, I can confirm that.

  • Where in the wp-admin? its throwing a “acf not defined” js error on post edit page where ACF fields are present. Thanks.

    • papijo

    • March 2, 2020 at 9:53 am

    Where in the wp-admin?

    • papijo

    • March 2, 2020 at 9:48 pm

    @adammontague
    Could you please specify the exact name & location of the script/file where your script must be inserted?
    “in your admin” is quite vague!
    I wonder how other posters found that info, but they must have found it, since they reported the fix did work.

  • @papijo maybe on admin_init hook

  • @papijo You save the script written by @adammontague above into a .js file (in my case I called it acf-fix.js), then you load the script into the admin screens using the following in your functions.php file:

    add_action( 'admin_enqueue_scripts', function() {
        wp_enqueue_script( 'handle', get_stylesheet_directory_uri() . '/js/acf-fix.js', array( 'jquery' ) );
    } );

    Be sure to check the file location is correct. get_stylesheet_directory_uri() refers to the theme root and I saved acf-fix.js into a /js folder, your case may be different.

    As noted above, the script written by @adammontague works, but does trigger a JS acf not defined error, which impacts other WP admin functionality such as tabs and menu hover states. So until a fix is found I simply turn on and off this script in functions.php as I need to use it.

    • papijo

    • March 3, 2020 at 2:45 am

    Thanks for the prompt reply, @alex-jordan
    I did all you explained, I do get the “ACF IS HERE!” message in my console, and I also get the error message Uncaught ReferenceError: acf is not defined at acf-fix.js?ver=5.3.2:7
    but… the fix does not work, my pins are automatically moved to the nearest road/street.
    Using the fix on ACF Pro Version 5.8.7.
    Let’s hope this bug is fixed any time soon…

  • Thanks Alex

  • Looks like today’s release 5.8.8 has fixed this 🙂 Thanks to those involved.

    • papijo

    • March 6, 2020 at 9:42 am

    Just to confirm that updating to Version 5.8.8 fixed the problem. Thanks a lot!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.