如何在asp.net中獲取當前的經緯度。我有這個代碼,但它沒有返回數據。它不屬於警戒html5中的地理位置
<script type='text/javascript' language="javascript">
function getUserLock() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(displayResult, displayError);
}
else {
setMessage("Geolocation is not supported by this browser");
}
}
function displayResult(position) {
setMessage("Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude);
PageMethods.SendLocation(position.coords.latitude, position.coords.longitude, onComplete, onFailed);
alert ('test');
}
function setMessage(msg) {
// document.forms[0].myLoc.value = msg;
}
function displayError(error) {
var errors = { 1: 'Permission denied', 2: 'Position unavailable', 3: 'Request timeout' };
setMessage("Error occured: " + errors[error.code]);
}
function onComplete(args) {
if (args)
alert('Log in oldunuz');
else
alert('İşlem Başarısız Oldu. Yeniden Deneyiniz...');
}
function onFailed(error) {
alert('Yapılan işlem sırasında aşağıdaki hata(lar) oluştu.\n\r' + error.get_message());
}
</script>
這是按鈕
<asp:Button ID="LoginButton" runat="server" Text="Log In" ValidationGroup="LoginUserValidationGroup"
OnClientClick="getUserLock();" OnClick="LoginButton_Click" />
如果你把一個警報,並您的JavaScript獲得的緯度和經度?那將是最好的起點。 – 2011-12-28 22:21:48
我嘗試了一下,但沒有失敗。首先用戶點擊myLogIn按鈕,瀏覽器詢問允許或拒絕。但在一秒鐘內,它會自動消失 – ozkank 2011-12-28 22:24:49
那麼你的問題與緯度或經度無關嗎? – 2011-12-29 15:55:58