位置地理编码解析问题

时间:2017-12-20 06:32:43

标签: javascript asp.net google-maps

这是我在输入数据时记录用户位置的表单,但是当解析器纬度和经度进入地址时我会遇到问题。我尝试用ID =地址调用地理编码,但我什么都没有,请帮忙。感谢

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

function initGeolocation()
 {
    if( navigator.geolocation )
    {
       // Call getCurrentPosition with success and failure callbacks
       navigator.geolocation.getCurrentPosition( success, fail );
    }
    else
    {
     alert("Sorry, your browser does not support geolocation services.");
    };
 };

 function success(position)
 {

 document.getElementById('Longitude').value = position.coords.longitude ;
 document.getElementById('Latitude').value = position.coords.latitude;

 };

 function fail(position)
 {
     // Could not obtain location

     window.location.href = "Default.aspx";
 };

 function codeLatLng() {
     var lat = document.getElementById('Latitude').value;
     var lng = document.getElementById('Longitude').value;

     var latlng = new google.maps.LatLng(lat, lng);
 geocoder.geocode({ 'latLng': latlng }, function (results, status) {
 if (status == google.maps.GeocoderStatus.OK && lat != "" && lng != "") {
             if (results[1]) {
                 map.setZoom(11);
                 marker = new google.maps.Marker({
                     position: latlng,
                     map: map
                 });
                 var address = (results[1].formatted_address);
 document.getElementById('Address').value = results[1].formatted_address;
                 infowindow.setContent(results[1].formatted_address);


                 infowindow.open(map, marker);
             } else {
                 alert("No results found");
             }
         } else {
             alert("Geocoder failed due to: " + status);
         }
     });
 };

 initGeolocation();
 codeLatLng();
 </script>

我用这个称呼地理编码:

 <asp:TextBox ID="Address" runat="server" Enabled="False"></asp:TextBox>
 <asp:TextBox ID="Latitude" runat="server" Enabled="False"></asp:TextBox><asp:TextBox ID="Longitude" runat="server" Enabled="False"></asp:TextBox>

我的texbox什么也没显示 而且

0 个答案:

没有答案