Center map on browsers location

Home Forums Calendar Products Events Calendar PRO Center map on browsers location

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #998114
    Scott
    Participant

    How can I pass the users current location to the map view so the map is centered to the current location. Obviously this would be a great advantage to mobile users and not too bad for desktops also.

    HTML5 will get me the current lat/lng, but need to pass to the map view, as if it was a geosearch.

    #998189
    George
    Participant

    Sorry Scott, this is unfortunately a customization request that is a bit too involved to fit within the scope of our support forums.

    You’re off to a good start, indeed, by getting the lat & long via HTML. With this in mind, take a look at resources/tribe-events-ajax-maps.js in your Events Calendar Pro plugin files – around line 104 or so you should see an options object like this:


    var options = {
    zoom : 5,
    center : new google.maps.LatLng( TribeEventsPro.geocenter.max_lat, TribeEventsPro.geocenter.max_lng ),
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    See how options.center is referring to two values, TribeEventsPro.geocenter.max_lat and TribeEventsPro.geocenter.max_lng?

    These values come from Tribe/Geo_Loc.php’s estimate_center_point() method, and is made available to the page via wp_localize_script() in Tribe/Main.php’s enqueue_pro_scripts() method.

    So, if you check out this enqueue_pro_scripts() method, you can see that the data being localized is filterable. This is probably your best bet for a simple way of altering this data.

    You’d do so like this:

    add_filter( 'tribe_events_pro_localize_script', 'scott_998114_new_map_center_point' );

    function scott_998114_new_map_center_point( $data ) {

    $data['geocenter']['max_lng'] = 'YOUR CUSTOM LNG VALUE';
    $data['geocenter']['max_lat'] = 'YOUR CUSTOM LAT VALUE';

    return $data;
    }

    If you can get the user’s location info, like by IP address or something, I’d recommend doing so and using this filter.

    Otherwise, then if all you have is the HTML5 data, then you can probably just overwrite the JavaScript object values for TribeEventsPro.geocenter.max_lat and TribeEventsPro.geocenter.max_lng on the page. There are numerous ways to go about doing that.

    Play around with things and hopefully you’re able to put something useful together.

    Best of luck with your customization!

    #1002490
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Center map on browsers location’ is closed to new replies.