Note that there are some explanatory texts on larger screens.

plurals
  1. POopenstreetmap geolocation
    primarykey
    data
    text
    <p>I'm newbie, I'm reading in internet the possibilities of openstreetmap, and also I read about openlayers...What I need, for begin, is obtain the location and create the corresponding map...I found a good example with openlayers, this is the code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;HTML5 geolocation with Openstreetmap and OpenLayers&lt;/title&gt; &lt;style type="text/css"&gt; html, body, #basicMap { width: 240; height: 320; margin: 10; } &lt;/style&gt; &lt;script src="http://openlayers.org/api/OpenLayers.js"&gt;&lt;/script&gt; &lt;script&gt; function init() { map = new OpenLayers.Map("basicMap"); var mapnik = new OpenLayers.Layer.OSM(); map.addLayer(mapnik); navigator.geolocation.getCurrentPosition(function(position) { document.getElementById('anzeige').innerHTML="Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude + "&lt;p&gt;"; var lonLat = new OpenLayers.LonLat(position.coords.longitude, position.coords.latitude) .transform( new OpenLayers.Projection("EPSG:4326"), //transform from WGS 1984 map.getProjectionObject() //to Spherical Mercator Projection ); markers.addMarker(new OpenLayers.Marker(lonLat)); map.setCenter(lonLat, 14 // Zoom level ); }); //map = new OpenLayers.Map("basicMap"); //var mapnik = new OpenLayers.Layer.OSM(); //map.addLayer(mapnik); map.setCenter(new OpenLayers.LonLat(3,3) // Center of the map .transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection ), 15 // Zoom level ); var markers = new OpenLayers.Layer.Markers( "Markers" ); map.addLayer(markers); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="init();"&gt; &lt;center&gt; HTML5 geolocation: &lt;br&gt; &lt;div id="basicMap"&gt;&lt;/div&gt; &lt;br&gt;HTML5 geolocation&lt;br&gt; &lt;br&gt;with Openstreetmap and OpenLayers&lt;br&gt; For Android Froyo,iPhone,iPAD,iPod &lt;br&gt; Your position estimated by browser geolocation API:&lt;p&gt; &lt;div id="anzeige"&gt;(will be displayed here)&lt;p&gt;&lt;/div&gt; &lt;a href="http://www.dr-bischoff.de"&gt;Andreas Bischoff&lt;/a&gt; &lt;br&gt;(view source to see how it works &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>You can see a live example here: <a href="http://www.pediaphon.org/~bischoff/location_based_services/" rel="nofollow noreferrer">http://www.pediaphon.org/~bischoff/location_based_services/</a> Next step, I need draw a scretch line which displays the rute followed. Here is a live example of drawing lines (pressing shift + clicking on mouse): <a href="http://openlayers.org/dev/examples/draw-feature.html" rel="nofollow noreferrer">http://openlayers.org/dev/examples/draw-feature.html</a></p> <p>But I'm new and I'm lost in how call api of openlayers in order to draw line from origin to destination...any help is welcome</p> <p>Best regards. </p> <p><strong>EDIT:</strong> I just copied this peace of code ( <a href="https://stackoverflow.com/questions/2735944/drawing-a-path-with-a-line-in-openlayers-using-javascript">Drawing a path with a line in OpenLayers using JavaScript</a> ) just before the tag, but I don't see the line drawn:</p> <pre><code> var lineLayer = new OpenLayers.Layer.Vector("Line Layer"); map.addLayer(lineLayer); map.addControl(new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path)); var points = new Array( /*I put these coords of my city*/ new OpenLayers.Geometry.Point(-3.7904085, 37.76225609999999 ), new OpenLayers.Geometry.Point(-4.7904085, 39.76225609999999 ) ); var line = new OpenLayers.Geometry.LineString(points); var style = { strokeColor: '#0000ff', strokeOpacity: 0.5, strokeWidth: 5 }; var lineFeature = new OpenLayers.Feature.Vector(line, null, style); lineLayer.addFeatures([lineFeature]); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload