Home › Forums › Calendar Products › Events Calendar PRO › Center map on browsers location
- This topic has 2 replies, 3 voices, and was last updated 8 years, 8 months ago by Support Droid.
-
AuthorPosts
-
August 21, 2015 at 6:11 pm #998114ScottParticipant
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.
August 22, 2015 at 10:34 am #998189GeorgeParticipantSorry 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!
September 6, 2015 at 7:05 am #1002490Support DroidKeymasterThis 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. -
AuthorPosts
- The topic ‘Center map on browsers location’ is closed to new replies.