Is it possible to center the map based of my visitor Geolocalisation

New home Forums Gold Add-on General queries Is it possible to center the map based of my visitor Geolocalisation

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by  louisp 1 year, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #34035

    louisp
    Member

    Hello,
    i need to set a map centered on my visitor location with a precise diameter 2km around my visitor location.
    Is it possible with this plugin ??

    Thanks,
    Louis

    #34049

    Dylan
    Moderator

    Hi Louis,

    Thanks for getting in touch with us.

    Unfortunately, it is not possible to draw the exact radius around the current user location as you required with the native features of the plugin.

    With WP Google Maps Pro it is possible to enable the user location and put a custom pin on the map on the coordinates of the user. Please note that this feature requires HTTPS on Chrome browsers, https://www.wpgmaps.com/use-my-location-requires-https-in-chrome/.

    It would possible to center the map on the user location with a small customization. One example you can take a look at can be found here page: https://www.wpgmaps.com/challenge-on-hover-over-element-changes-map-centre-and-zoom/ – We could base the basic changes on the document found there by simply emulating a click on the user’s dropped pin.

    I would be more than happy to help you with these changes if you are interested in moving forward with them.

    Let me know if I can help you with anything else.

    #34065

    louisp
    Member

    The trick to simulate the click on the dropped pin is enough to get the feature i need.
    But i tried to follow the post instruction and it does not work.
    I need a bit of help.

    #34155

    louisp
    Member

    Hello Dilan,
    i need support to implement this trick it does not work.

    #34157

    SupportTeam
    Moderator

    Hi Louis,

    I’ve created a little customization to center the map on the user location right after the page loads. To apply it do the following:

    Enable the Google Maps Pro plugin ‘show user location’:

    1 – Navigate to ‘Maps -> Click on the edit link of a map in the list -> Select the Advanced Settings tab’
    2 – Turn the ‘Show User’s Location?’ switch on
    3 – (Optional) select a custom icon for the location of a user

    Create the function that centers the map on the location of a user

    1 – Navigate to ‘Plugins -> Editor -> Select WP Google Maps Pro -> Select the /js/core.js file’
    2 – Find the strings ‘tabsshow’ or ‘tabsactivate’, within the code editor, which must have the core.js file loaded on it

    jQuery(‘body’).on(‘tabsactivate’, function(event, ui) {
    for(var entry in wpgmaps_localize) {
    InitMap(wpgmaps_localize[entry][‘id’],’all’,false);
    }
    });
    jQuery(‘body’).on(‘tabsshow’, function(event, ui) {
    for(var entry in wpgmaps_localize) {
    InitMap(wpgmaps_localize[entry][\’id\’],\’all\’,false);
    }
    });

    3 – Paste the code within the ‘// Customization’ tags right after the jQuery event of the ‘tabsshow’ string:

    ..

    jQuery(‘body’).on(‘tabsshow’, function(event, ui) {
    for(var entry in wpgmaps_localize) {
    InitMap(wpgmaps_localize[entry][‘id’],’all’,false);
    }
    });

    // Customization
    // Center all maps of the page on the current user location on page load
    //setTimeout(function(){
    jQuery(“.wpgmza_map”).each(function() {

    try {
    var rawmMapId = jQuery(this).attr(“id”);
    var mapId = rawmMapId.replace(“wpgmza_map_”,””);

    navigator.geolocation.getCurrentPosition(function(position) {
    var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    var myMap = MYMAP[mapId];

    if (typeof(myMap) !== “undefined”) {
    MYMAP[mapId].map.setCenter(userLatLng);
    }
    });
    } catch (err) {
    console.log(“Failed to perform custom map feature: focus on user location ” + err);
    }
    });

    4 – Click on the ‘Update file’ button at the bottom of the page

    I hope it helps,

    #34189

    SupportTeam
    Moderator

    Hi Louis,

    I’m so glad to hear!

    If you ever have two minutes spare, please consider reviewing the plugin on https://wordpress.org/support/plugin/wp-google-maps/reviews/#new-post – it would mean the world to me!

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

You must be logged in to reply to this topic.