I have a problem in the User location variable I can't use it after on my website! I received an error message that this variable is not defined!! I can't use the values of latitude and longitude to put it in a variable. please any solution?[
// On initialise la latitude et la longitude de Paris (centre de la carte)
var lat = 48.3903;
var lon = -4.4863;
var map = null;
// Fonction d'initialisation de la carte
function initMap() {
// Créer l'objet "map" et l'insèrer dans l'élément HTML qui a l'ID "map"
map = new google.maps.Map(document.getElementById("map"), {
// Nous plaçons le centre de la carte avec les coordonnées ci-dessus
center: new google.maps.LatLng(lat, lon),
// Nous définissons le zoom par défaut
zoom: 14,
// Nous définissons le type de carte (ici carte routière)
mapTypeId: google.maps.MapTypeId.ROADMAP,
// Nous activons les options de contrôle de la carte (plan, satellite...)
mapTypeControl: true,
// Nous désactivons la roulette de souris
scrollwheel: false,
mapTypeControlOptions: {
// Cette option sert à définir comment les options se placent
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
// Activation des options de navigation dans la carte (zoom...)
navigationControl: true,
navigationControlOptions: {
// Comment ces options doivent-elles s'afficher
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
var x = document.getElementById("demo");
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
//*************************** ON THIS IS MY QUESTION **********************************
var UserLocation = [position.coords.latitude,position.coords.longitude];
var marker = new google.maps.Marker({
position: pos,
map: map,
title: 'Here you are',
draggable: true
});
});
}
][1]