This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Geo-location on HTML page

0

Hi there

I'm looking for an easy solution how to add to my OpenStreetMap the icon to get my current position and retrive latitude and longitude.

Thanks in advance for your help. Please keep ion mind when relying that I'm a nook.

best regards

Ossy

asked 13 Oct '20, 10:28

Ossy01's gravatar image

Ossy01
11112
accept rate: 0%

edited 13 Oct '20, 10:54

TZorn's gravatar image

TZorn
12.3k764225

Can you explain in a bit more detail what you mean by "my OpenStreetMap"? If a generic website, try one of https://duckduckgo.com/?t=ffsb&q=html+geolocation&ia=web .

(13 Oct '20, 10:35) SomeoneElse ♦

Sorry about not being clear. Here is my Page. <html><body>

<script src="http://www.openlayers.org/api/OpenLayers.js"></script> <script> var mylat = 46.9 var mylon = 6.6833 map = new OpenLayers.Map("mapdiv"); map.addLayer(new OpenLayers.Layer.OSM());

var lonLat = new OpenLayers.LonLat( mylon,mylat )
      .transform(
        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
        map.getProjectionObject() // to Spherical Mercator Projection
      );
var zoom=17;
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonLat));
map.setCenter (lonLat, zoom);

</script> </body></html>

I would lite to add under the zoom the icon for geo-location, center the map to this location and retrieve the information in my javascript. I have seen some script, but I didn't work for me. Perhars not used corretly.

++ Ossy

(13 Oct '20, 10:49) Ossy01

Source code available on GitHub .