Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Geolocation openstreetmap地理定位_Geolocation_Openlayers_Openstreetmap - Fatal编程技术网

Geolocation openstreetmap地理定位

Geolocation openstreetmap地理定位,geolocation,openlayers,openstreetmap,Geolocation,Openlayers,Openstreetmap,我是新手,我正在互联网上阅读openstreetmap的可能性,我也阅读了有关openlayers的内容……首先,我需要获取位置并创建相应的地图……我发现了一个关于openlayers的好例子,代码如下: <html> <head> <title>HTML5 geolocation with Openstreetmap and OpenLayers</title> <style type="text/css">

我是新手,我正在互联网上阅读openstreetmap的可能性,我也阅读了有关openlayers的内容……首先,我需要获取位置并创建相应的地图……我发现了一个关于openlayers的好例子,代码如下:

<html>
  <head>
    <title>HTML5 geolocation with Openstreetmap and OpenLayers</title>
    <style type="text/css">
      html, body, #basicMap {
          width: 240;
          height: 320;
          margin: 10;
      }
    </style>

    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    <script>
      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 + "<p>";
            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);

      }
    </script>

  </head>

  <body onload="init();">
<center>
HTML5 geolocation:
<br>
    <div id="basicMap"></div>
<br>HTML5 geolocation<br>
<br>with Openstreetmap and OpenLayers<br>
For Android Froyo,iPhone,iPAD,iPod
<br>
Your position estimated by browser geolocation API:<p>

<div id="anzeige">(will be displayed here)<p></div>
<a href="http://www.dr-bischoff.de">Andreas Bischoff</a>

<br>(view source to see how it works 
</center>
  </body>
</html>
丹尼尔

这个问题已经在这里讨论过了

    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]);