使用Google maps api查看空白页面

时间:2013-04-23 12:12:53

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

根据以下链接,我正在尝试使用Google地图,用户可以点击地图指定位置,但我只看到一个空白屏幕: https://developers.google.com/maps/articles/phpsqlinfo_v3

我在这里根据链接进行了一些更改,但它没有改变: webview for google maps v3 shows blank screen

Google Chrome控制台中的错误如下: 未捕获的SyntaxError:意外的令牌< phpsqlinfo_add.html:33 未捕获的ReferenceError:初始化未定义phpsqlinfo_add.html:123

下面在代码中突出显示了适当的行:

<!DOCTYPE html>
<!--
 Copyright 2008 Google Inc.
 Licensed under the Apache License, Version 2.0:
 http://www.apache.org/licenses/LICENSE-2.0
 -->
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Saving User-Added Form Data Example</title>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    var marker;
    var infowindow;

    function initialize() {
      var latlng = new google.maps.LatLng(37.4419, -122.1419);
      var options = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      google.maps.event.addDomListener(window, 'load', initialize);
      var map = new google.maps.Map(document.getElementById("map_canvas"), options);
      var html = "<table>" +
                 "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
                 "<tr><td>Email:</td> <td><input type='text' id='email'/></td> </tr>" +
                 "<tr><td>Phone:</td> <td><input type='text' id='phone'/></td> </tr>" +
                 "<tr><td>Town:</td> <td><input type='text' id='town'/></td> </tr>" +
                 "<tr><td>County:</td> <td><select id='county'>" +
                 **<option value='Outside Ireland' SELECTED>OutsideIreland</option> +**
                 <option value='Antrim' SELECTED>Antrim</option> +
                 <option value='Armagh' SELECTED>Armagh</option> +
                 <option value='Carlow' SELECTED>Carlow</option> +
                 <option value='Cavan' SELECTED>Cavan</option> +
                 <option value='Clare' SELECTED>Clare</option> +
                 <option value='Cork' SELECTED>Cork</option> +
                 <option value='Derry' SELECTED>Derry</option> +
                 <option value='Donegal' SELECTED>Donegal</option> +
                 <option value='Down' SELECTED>Down</option> +
                 <option value='Dublin' SELECTED>Dublin</option> +
                 <option value='Fermanagh' SELECTED>Fermanagh</option> +
                 <option value='Galway' SELECTED>Galway</option> +
                 <option value='Kerry' SELECTED>Kerry</option> +
                 <option value='Kildare' SELECTED>Kildare</option> +
                 <option value='Kilkenny' SELECTED>Kilkenny</option> +
                 <option value='Laois' SELECTED>Laois</option> +
                 <option value='Leitrim' SELECTED>Leitrim</option> +
                 <option value='Limerick' SELECTED>Limerick</option> +
                 <option value='Longford' SELECTED>Longford</option> +
                 <option value='Louth' SELECTED>Louth</option> +
                 <option value='Mayo' SELECTED>Mayo</option> +
                 <option value='Meath' SELECTED>Meath</option> +
                 <option value='Monaghan' SELECTED>Monaghan</option> +
                 <option value='Offaly' SELECTED>Offaly</option> +
                 <option value='Roscommon' SELECTED>Roscommon</option> +
                 <option value='Sligo' SELECTED>Sligo</option> +
                 <option value='Tipperary' SELECTED>Tipperary</option> +
                 <option value='Tyrone' SELECTED>Tyrone</option> +
                 <option value='Waterford' SELECTED>Waterford</option> +
                 <option value='Westmeath' SELECTED>Westmeath</option> +
                 <option value='Wexford' SELECTED>Wexford</option> +
                 <option value='Wicklow' SELECTED>Wicklow</option> +
                 "</select> </td></tr>" +
                 "<tr><td>Name of Location:</td> <td><input type='text' id='location'/></td> </tr>" +
                 "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";

    infowindow = new google.maps.InfoWindow({
     content: html
    });

    google.maps.event.addListener(map, "click", function(event) {
        marker = new google.maps.Marker({
          position: event.latLng,
          map: map
        });
        google.maps.event.addListener(marker, "click", function() {
          infowindow.open(map, marker);
        });
    });
    }

    function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var type = document.getElementById("type").value;
      var latlng = marker.getPosition();

      var url = "phpsqlinfo_addrow.php?name=" + name + "&address=" + address +
                "&type=" + type + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();
          document.getElementById("message").innerHTML = "Location added.";
        }
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request.responseText, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}
    </script>
  </head>

  <body>
  <div id="map_canvas" style="height: 100px; width=100px;"></div>
  **<script type="text/javascript">initialize();</script>**
</body>
  <!-- Commenting out line to edit suggestion from stackoverflow
  <body style="margin:0px; padding:0px;" onload="initialize()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
    <div id="message"></div>
  </body> -->
</html>

1 个答案:

答案 0 :(得分:2)

从这里开始语法无效:

**<option value='Outside Ireland' SELECTED>OutsideIreland</option> +**

看起来您正在尝试使用javascript连接语法options连接所有+。如果你走这条路线,那么你需要在所有options

周围添加双引号

另一条路线是删除所有+,并在html var字符串的开头和结尾处使用双引号。