使用Chrome插件中的标记打开Goog​​le地图

时间:2015-04-22 11:16:17

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

我正在开发一个应用程序,这个chrome扩展是该Web应用程序的一部分。每当用户启动此扩展时,它应显示带有预定义标记的地图。这是我编写test.html的示例代码

<html>
  <head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script src="http://maps.googleapis.com/maps/api/js"></script>
    <script>
      function initialize() {
        var mapProp = {
          center:new google.maps.LatLng(51.508742,-0.120850),
          zoom:5,
          mapTypeId:google.maps.MapTypeId.ROADMAP
        };
        var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>

  <body>
      <div id="loading">
        <div>
          <img src="img/sunny.png" />
          <p>Getting Data From Server</p>
        </div>
      </div>

      <div id="wrapper">
        <div id="weather"></div>
        <div id="googleMap" style="width:500px;height:380px;"></div>
      </div>
  </body>
</html>

Main.js

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('weather.html', {
    id: 'weather',
    innerBounds: {
      height: 450,
      width: 300,
    },
    resizable: true
  });
});

它会打开一个弹出窗口,但不会加载地图。虽然这个html文件在我直接在浏览器中打开时工作正常。

0 个答案:

没有答案