Support

Account

Home Forums Backend Issues (wp-admin) Programmatically update google map field in admin

Solving

Programmatically update google map field in admin

  • Hi,

    Is there a way to programmatically (via js) update the value of the google map field ?
    I’m retrieving the gps coordinates of an image when it’s uploaded but would like to update the google map field with these data, without submitting the post.

    So far, I’m able to change the input of the search bar, but it does not create a pin nor change the actual location of the map…

    Thanks,
    Clément

  • Hi Clément,

    I would guess the reason the map isn’t updated is because it does not recognise when the field is being filled programmatically. It might be solved by triggering the enter button after you’ve filled the field.

    Try something like this:

    var e = jQuery.Event("keydown");
    e.which = 50; // # Some key code value
    $("input").trigger(e);

    Are the values saved when you’re saving the post at least?

  • Hi Jonathan, thanks for the answer.

    I tried the code below, but the trigger doesn’t work (does nothing).

    This is my actual code (useful fragment):

    $(".acf-google-map .no-value input").val(latitude+" "+longitude).focus();
    var e = jQuery.Event("keydown");
    e.which = 13; // # key code value for 'Enter'
    $(".acf-google-map .no-value input").trigger(e);

    The value is not saved when i’m saving the post.

  • Hi,

    Hm okay. Could you try this instead:

    
    var e = jQuery.Event("keypress");
    e.which = 13; //choose the one you want
    e.keyCode = 13;
    $("#theInputToTest").trigger(e);
    

    And to clarify, your address is filled in to the input field correctly? I mean, you see the address added? Are you just filling it with GPS coordinates or an actual address?

  • Hi, thanks for your answer.

    I tried it, nothing happen. I also tried .submit() on the input, but it submits the whole post. And I tried to trigger a click on the link “find-location”, but not working.

    The address is filled with GPS coordinates, when I pressed enter myself it does work (it’s changing the location).

    Screenshots:
    After programmatically adding the gps coordinates:Google map field before I pressed Enter

    After I pressed ‘enter’ (myself, not programmatically) :Google map field after I pressed Enter

    Would be a way to do it through acf.add_filter(‘google_map_args’) ?

  • This is a very old post I know, but in case someone else stumbles upon this thread as I did…

    I got this to work using:

    jQuery('.acf-google-map .actions .-search').trigger('click');

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

The topic ‘Programmatically update google map field in admin’ is closed to new replies.