在谷歌街景api解析网址

时间:2012-06-24 00:06:37

标签: javascript google-maps google-maps-api-3

这是街景API V3的一个工作示例:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example: Street View Events</title>
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"
        type="text/javascript"></script>
<script type="text/javascript">

  var cafe = new google.maps.LatLng(37.869085,-122.254775);

  function initialize() {

    var panoramaOptions = {
      position: cafe,
      pov: {
        heading: 270,
        pitch: 0,
        zoom: 1
      },
      visible: true
    };
    var panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);

    google.maps.event.addListener(panorama, 'pano_changed', function() {
        var panoCell = document.getElementById('pano_cell');
        panoCell.innerHTML = panorama.getPano();
    });

    google.maps.event.addListener(panorama, 'links_changed', function() {
        var linksTable = document.getElementById('links_table');
        while(linksTable.hasChildNodes()) {
          linksTable.removeChild(linksTable.lastChild);
        };
        var links =  panorama.getLinks();
        for (var i in links) {
          var row = document.createElement("tr");
          linksTable.appendChild(row);
          var labelCell = document.createElement("td");
          labelCell.innerHTML = "<b>Link: " + i + "</b>";
          var valueCell = document.createElement("td");
          valueCell.innerHTML = links[i].description;
          linksTable.appendChild(labelCell);
          linksTable.appendChild(valueCell);
        }
    });

    google.maps.event.addListener(panorama, 'position_changed', function() {
        var positionCell = document.getElementById('position_cell');
        positionCell.firstChild.nodeValue = panorama.getPosition();
    });

    google.maps.event.addListener(panorama, 'pov_changed', function() {
        var headingCell = document.getElementById('heading_cell');
        var pitchCell = document.getElementById('pitch_cell');
        headingCell.firstChild.nodeValue = panorama.getPov().heading;
        pitchCell.firstChild.nodeValue = panorama.getPov().pitch;
    });
}
</script>
</head>
<body onload="initialize()">
  <div id="pano" style="width: 425px; height: 240px;float:left"></div>
  <div id="panoInfo" style="width: 425px; height: 240 px;float:left">
  <table>
  <tr>
    <td><b>Position</b></td><td id="position_cell">&nbsp;</td>
  </tr>
  <tr>
    <td><b>POV Heading</b></td><td id="heading_cell">270</td>
  </tr>
  <tr>
    <td><b>POV Pitch</b></td><td id="pitch_cell">0.0</td>
  </tr>
  <tr>
    <td><b>Pano ID</b></td><td id="pano_cell">&nbsp;</td>
  </tr>
  <table id="links_table">
  </table>
  </table>
  </div>
</body>
</html>

我一整天都在搜索如何将谷歌地图街景网址解析为谷歌地图街景嵌入javascript,但我似乎无法在任何地方找到解决方案,需要解析这样的事情:{{3} }

2 个答案:

答案 0 :(得分:1)

有这个查询字符串库:https://github.com/visionmedia/node-querystring。适用于node.js和浏览器。

答案 1 :(得分:0)

pano position = 37.588929,-87.337506“ll =” 看起来“cbp =”会给你标题,音高和变焦

http://www.geocodezip.com/v3_GoogleEx_streetview-simpleA.htm

请参阅this page on mapki.com了解其含义。

更新(mapki.com似乎已经消失): 根据这个site

“cbp =”的5个部分是窗口大小,航向(方位),倾斜,缩放和俯仰(按此顺序)。