Bonjour je veux dessiner un point qui précise ma localisation firebug ne retourne aucun bug mais rien ne s'affiche j'ai besoin de votre aide merci :)
//this is outside the init() openlayers function. If i put it inside init(), will not work at all
function loadDemo() {
if(navigator.geolocation) {
document.getElementById("support").innerHTML = "I'll find you!";
navigator.geolocation.getCurrentPosition(updateLoc ation, handleLocationError, {timeout:100000});
} else {
document.getElementById("support").innerHTML = "Browser is so old";
}}
function handleLocationError(){
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
function updateLocation(position) {
var latitudeg = position.coords.latitude;
var longitudeg = position.coords.longitude;
var accuracy = position.coords.accuracy;
document.getElementById("latitude").innerHTML = latitudeg;//works
document.getElementById("longitude").innerHTML = longitudeg;//works
document.getElementById("accuracy").innerHTML = "This location is accurate within " +accuracy + " meters."//works
var lonLat = new OpenLayers.LonLat(longitudeg,latitudeg).transform( new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"));//works
alert(lonLat);//works
console.log("here is lonlat"+lonLat);
var pointg = new OpenLayers.Geometry.Point(longitudeg, latitudeg);
pointg.transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
);
console.log("c'est un point"+pointg);
var feature_point_g = new OpenLayers.Feature.Vector (pointg,null,null);
console.log ("sss"+feature_point_g.geometry.toString());
vectors = new OpenLayers.Layer.Vector("Vector Layer");
alert(pointg.lat);
alert(feature_point_g);
vectors.addFeatures([feature_point_g]);
map.addLayer(vectors);
}
//this is outside the init() openlayers function. If i put it inside init(), will not work at all
function loadDemo() {
if(navigator.geolocation) {
document.getElementById("support").innerHTML = "I'll find you!";
navigator.geolocation.getCurrentPosition(updateLoc ation, handleLocationError, {timeout:100000});
} else {
document.getElementById("support").innerHTML = "Browser is so old";
}}
function handleLocationError(){
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
function updateLocation(position) {
var latitudeg = position.coords.latitude;
var longitudeg = position.coords.longitude;
var accuracy = position.coords.accuracy;
document.getElementById("latitude").innerHTML = latitudeg;//works
document.getElementById("longitude").innerHTML = longitudeg;//works
document.getElementById("accuracy").innerHTML = "This location is accurate within " +accuracy + " meters."//works
var lonLat = new OpenLayers.LonLat(longitudeg,latitudeg).transform( new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"));//works
alert(lonLat);//works
console.log("here is lonlat"+lonLat);
var pointg = new OpenLayers.Geometry.Point(longitudeg, latitudeg);
pointg.transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
);
console.log("c'est un point"+pointg);
var feature_point_g = new OpenLayers.Feature.Vector (pointg,null,null);
console.log ("sss"+feature_point_g.geometry.toString());
vectors = new OpenLayers.Layer.Vector("Vector Layer");
alert(pointg.lat);
alert(feature_point_g);
vectors.addFeatures([feature_point_g]);
map.addLayer(vectors);
}