Saving marker data to cookie onclick

New home Forums Pro Add-on General queries Saving marker data to cookie onclick

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #21576
    totebox
    Member

    Hi,

    I am looking to save relevant marker data (lat/long, title) when the user clicks on the marker to a cookie for access by another page. Any ideas how to do this? Would really appreciate any pointers.

    #21605
    Dylan
    Moderator

    Hi there,

    Thank you so much for getting in touch with us.

    I believe the easiest way for you to achieve this would be to use jQuery.Cookie to set and get cookies once the user has clicked on a marker.

    In order to store the relevant data you will need to make some changes to the ‘wpgmza_open_marker_func’ function within the core.js (wp-google-maps-pro/js/core.js) file.

    Specifically you would add the following code to the top of the function (above the first jQuery call):

    
    var gps = marker_data.gps;
    var latlng = gps.split(","); //Gets the lat/lng
    
    Cookies.set('marker_title', marker_data.title , { expires: 1, path: '/' }); //sets title
    Cookies.set('marker_lat', latlng[0] , { expires: 1, path: '/' }); //sets lat
    Cookies.set('marker_lng', latlng[1] , { expires: 1, path: '/' }); //sets long
    

    Although this is a rough example, this should store the following cookies on the page:
    – marker_title
    – marker_lat
    – marker_lng

    To retrieve a cookie with jQuery Cookie, simple use the following:

    
    Cookies.get('marker_title');
    

    I hope this helps?

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.