Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have managed to show Lat and Lon

      function init() {

        navigator.geolocation.getCurrentPosition(function(position) {
            document.getElementById('myloc').innerHTML="Latitude: " + position.coords.latitude + "   Longitude: " +
            position.coords.longitude + "<p>";
        });
      }

now i want this lat and lon on OSM map as a point and whenever i refresh the page, I want the point follows my location...

I added this code in my map function itin

var vectorpoint = new OpenLayers.Layer.Vector("VectorPoint");
map.addLayer(vectorpoint);
var point = new OpenLayers.Geometry.Point(position.coords.longitude ,position.coords.latitude);
vector.addFeatures(new OpenLayers.Feature.Vector(point));

any suggestion?

share|improve this question
add comment

2 Answers

You could use a marker layer with a image for easy rendering if you only want a simple marker.

Also you will need to center the map to the desired location. With a OpenLayers.Layer.Vector you can do it easily:

  (OpenLayers.Map).zoomToExtent( (OpenLayers.Layer.Vector).getDataExtent() );

To make the "follow" thing you will need a timer to update the feature point regularly.

share|improve this answer
add comment

I think the only part of the code missing is the center on the point, right?

If the layer has only that point, you can zoom to the layer extent.

If the layer has more than one point, you can zoom to the coordinates.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.