I am trying to dynamically load a KML file into a map depending on which buddy press user is logged in. Everything works fine when I hardcode a userID in the javascript file, but I need it to dynamically load the current user user ID.
Here is the javascript file:
function initialize(){
//MAP
//manually set user ID to zero
//var current_user =0;
var current_user;
//var current_user = "<?php get_currentuserinfo(); echo $current_user->ID?>"
var latlng = new google.maps.LatLng(90.64138205695923,-45.38903528363647);
var options = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), options);
var kmlLayer = new google.maps.KmlLayer('http://www.mysite.com/timeline_'+current_user+'.kml');
kmlLayer.setMap(map);
This is what i have in the php file, within the loop:
$("#address1").click( function() {
initialize();
var currentUser = <?php get_currentuserinfo(); echo $current_user->ID?>;
$current_user = currentUser;
});
Like I mentioned, it works if i hard code the user ID, but I am not sure how to pass the UserID from PHP to the javascript file.