如何获取当前地理位置

krpano中文网问答区分类: 问答区如何获取当前地理位置
krpano中文网 管理员 asked 4年 ago

如何获取当前地理位置

1 Answers
krpano中文网 管理员 answered 4年 ago
<action name="get_geo_location" type="Javascript"><![CDATA[
        
    krpano.actions.showlog();
    
    if ("geolocation" in navigator)
    {
        navigator.geolocation.getCurrentPosition( 
            function(position)
            {
                krpano.trace(1,"latitude=" + position.coords.latitude);
                krpano.trace(1,"longitude=" + position.coords.longitude);
                krpano.trace(1,"heading=" + position.coords.heading);
            },
            function(err)
            {
                krpano.trace(1,"geolocation error: "+err.message);
            }
        );
    }
    else
    {
        krpano.trace(1,"no geolocation support by the browser");
    }
]]></action>
    
<!-- a button for testing: -->
<layer name="get_geo_location" keep="true"
    type="text"
    html="Get Geo Location"
    align="center"
    onclick="get_geo_location();"
    />

Your Answer

2 + 7 =