地理位置在HTML5 [英] geolocation in html5

查看:135
本文介绍了地理位置在HTML5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让asp.net当前的经纬度。我有这个code,但它并没有返回数据。它不属于警戒

 <脚本类型=文/ JavaScript的'语言=JavaScript的>
    功能getUserLock(){
        如果(navigator.geolocation){            navigator.geolocation.getCurrentPosition(displayResult,displayError);
        }
        其他{
            setMessage(地理位置是此浏览器不支持);
        }
    }    功能displayResult(位置){
        setMessage(纬度:+ position.coords.latitude +,经度:+ position.coords.longitude);
        PageMethods.SendLocation(position.coords.latitude,position.coords.longitude,的onComplete,onFailed);
        警报('测试');
    }    函数setMessage(MSG){
        // document.forms [0] = .myLoc.value味精;
    }    功能displayError(错误){
        VAR误差= {1:'权限被拒绝',2:位置不可用,3:'请求超时'};
        setMessage(发生错误:+错误[错误code]);
    }    功能的onComplete(参数){
        如果(参数)
            警报('登录oldunuz');
        其他
            警报('。İşlemBaşarısızOldu Yeniden Deneyiniz ...');
    }    功能onFailed(错误){
        警报('Yapılanişlemsırasındaaşağıdaki哈塔(LAR)oluştu\\ n \\ r'+ error.get_message());
    }< / SCRIPT>

这是按钮

 < ASP:按钮的ID =LoginButton=服务器文本=登录的ValidationGroup =LoginUserValidationGroup
                的OnClientClick =getUserLock();的OnClick =LoginButton_Click/>


解决方案

有可能是几个问题在这里:

为了能够使用PageMethods容器在JavaScript中,你需要

首先,装点[WebMethod]属性您的方法。你只被允许使用静态方法!

  [的WebMethod]
公共静态字符串的HelloWorld(字符串名称)
{
   返回你好,世界。我在+名称;
}

二,启用PageMethods的支持

 < ASP:的ScriptManager ID =ScriptManager1=服务器的EnablePageMethods =真/>

我也想通过提供相应的功能处理的函数添加错误处理一些支持:从PageMethods每次调用花费的调用可能取得的成果,以及其他一些参数的参数

how to get current latitude and longitude in asp.net. i have this code, but it didn't return data. it's not fall alert

  <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>

this is button

 <asp:Button ID="LoginButton" runat="server" Text="Log In" ValidationGroup="LoginUserValidationGroup"
                OnClientClick="getUserLock();" OnClick="LoginButton_Click" />

解决方案

There can be several issues here:

In order to be able to use PageMethods container in JavaScript you need to

First, decorate your method with [WebMethod] attribute. You are only allowed to use the static methods!

[WebMethod]
public static string HelloWorld(string name)
{
   return "Hello, World. I am " + name;
}

Second, enable the support for PageMethods

<asp:ScriptManager ID="ScriptManager1″ runat="server" EnablePageMethods="True" />

I would also add some support for error handling by providing the appropriate function handlers to the function: every invocation from PageMethods takes parameters for possible outcomes of the invocations as well as some other parameters.

这篇关于地理位置在HTML5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆