function load avec géolocalisation
Bonjour,
Je possède une function comme ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| getLocation();
function getLocation(){
if (navigator.geolocation){
//show the geolocation position
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function showPosition(position){
var latitude = "" + position.coords.latitude + "";
var longitude = "" + position.coords.longitude + "";
window.alert(latitude+", "+longitude);
} |
A titre d'essai j'ai inséré une alert pour vérifier cette fonction.... résultat OK.
En dessous j'ai une autre fontion (load) ...... (map...Google).
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var center = new GLatLng(50.6371834, 3.0630174);
map.setCenter(center, 9);//zoom
geocoder = new GClientGeocoder();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML = center.lat().toFixed(7);
document.getElementById("lng").innerHTML = center.lng().toFixed(7); |
Je n'arrive pas à remplacer la latitude et la longitude, dans cette ligne :
Code:
var center = new GLatLng(50.6371834, 3.0630174);
J'ai essayé comme ceci, puisque le window.alert fonctionne bien :
Code:
var center = new GLatLng(latitude+", "+longitude);
Et...ça ne marche pas..
Comment faire pour insérer (var latitude et var longitude).
Merci par avance.
Bruno