如何将变量从JavaScript降级到经典ASP - GeoCoding

时间:2016-10-13 13:40:50

标签: javascript asp-classic

我希望能够将所请求的信息LAT,LONG和AddressField传递到ASP文本字段框,以便我可以在另一个asp页面中使用这些结果。

我能够在文本框中完成LAT和LONG并传递此信息。

我无法填写地址。

目前有一个默认地址字段,其中包含默认位置。它还允许用户输入地址。

submit上,代码会将地理编码信息返回到同一页面。

我可以填写LAT和LONG,但我无法填写地址。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <style>


  </style>

  <script src="http://maps.google.com/maps/api/js?key=API KEY & 
 sensor=false" type="text/javascript"></script>
  <script type='text/javascript'>
    window.onload = function () {
      // find DOM elements
      var latField = document.getElementById('lat');
      var lngField = document.getElementById('long');
      var canvas = document.getElementById('map');
      var form = document.getElementById('addressForm');
      var addressField = form.address;

      // create map, marker, infowindow and geocoder objects
      var options = {
        zoom: 10,
        center: new google.maps.LatLng(39.9611755, -82.99879420000002),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(canvas, options);
      var marker = new google.maps.Marker({
        map: map
      });
      var infowindow = new google.maps.InfoWindow();
      var geocoder = new google.maps.Geocoder();

      // set handler for form.onsubmit event
      form.onsubmit = function () {
        return showAddressOnMap(addressField.value);
      }

      // worker function to display marker on map at address
      function showAddressOnMap(address) {
        try {
          var geocoderRequest = {
            address: address
          }
          geocoder.geocode(geocoderRequest, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              var location = results[0].geometry.location;
              map.setCenter(location);
              marker.setPosition(location);
              var content = [];
              content.push('<strong>' + results[0].formatted_address +
                '</strong>');
              content.push('Lat: ' + location.lat());
              content.push('Lng: ' + location.lng());
              infowindow.setContent(content.join('<br/>'));
              infowindow.open(map, marker);
              latField.value = location.lat();
              lngField.value = location.lng();
            }
          });
          return false;
        } catch (e) {
          return false; //ensure form does not submit, even if there's an error
        }
      }
    };

  </script>
</head>

<body>

  <div id="map" style="width:500px;height:350px;border:1px solid #999;"></div>
  <form id="addressForm" style="margin:10px 0;">
    <input name="address" size="69" value="Columbus, Ohio"><br/>
    <input type="submit" value="Submit" />
  </form>
  <div style="font-family:'Lucida Console', Monaco, monospace;">
    </p>
  </div>
  <div>
    <form id="addressForm" name="address" method="post" action="test9.asp"> Address
    <label for="address"></label>
    <input name="address" type="text" id="address" size="69" />
    <p>
      <p>Lat
        <label for="lat"></label>
        <input type="text" name="lat" id="lat" />
      </p>
    </p>
    <p>Long
      <label for="Long"></label>
      <input type="text" name="Long" id="Long" />
    </p>
    <input type="submit" name="button" id="button" value="Submit" />
    </form>
    <p>&nbsp;</p>
  </div>
</body>

</html>

0 个答案:

没有答案