Gmaps Js和ASP.net文本框不断清除

时间:2014-06-04 00:50:40

标签: c# javascript asp.net google-maps hosting

我正在开发一个asp.net应用程序,当用户单击按钮时,该应用程序将在谷歌地图上显示当前位置。 这个想法是当用户点击" my-location"按钮和co-ords显示在文本框中,位置显示在地图上。

问题是这个代码在我的本地机器上完美运行,但是一旦我将它部署到HostGator,文本框就会被填充,并且会在一段时间后清除。

这是代码

asp.net按钮

<asp:Button ID="mylocation" runat="server" Text="My Location" OnClientClick="getLocation()" CssClass="my-location-button" title="My Location" ClientIDMode="Static"/>

javascript

 function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    var lat;
    var lng;

    lat = position.coords.latitude;
    lng = position.coords.longitude;

    //Google Maps
    var map2;
    var mapOptions = {
        zoom: 17
    };

    map2 = new google.maps.Map(document.getElementById('GMap1'),
        mapOptions);

    var pos = new google.maps.LatLng(lat, lng);                                            

    var infowindow = new google.maps.InfoWindow({
        map: map2,
        position: pos,
        content: 'You are here!'
    });

    map2.setCenter(pos);

    var marker = new google.maps.Marker({
        position: pos,
        map: map2
    });

    infowindow.open(map2, marker);

    //Display the lat and lng in txtbox
    var textBox1 = document.getElementById('fromtext');
    textBox1.value = lat + ", " + lng;


}

Google地图声明位于site.master中

                        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"> </script>

这个特定的代码怎么可能在本地和主机上运行它不会?

2 个答案:

答案 0 :(得分:0)

我只是在猜测,因为我还无法在问题中添加评论。您确定该页面未回发,请尝试从getLocation()方法返回false。

答案 1 :(得分:0)

我改变了

OnClientClick="getLocation()"

OnClientClick="return getLocation()" 

并在我的函数中添加了返回false并且它正常工作:)感谢您的帮助

相关问题