js es定位

来源:互联网 发布:linux ioctlsocket 编辑:程序博客网 时间:2024/06/05 15:04
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/reqwest/2.0.5/reqwest.min.js"></script>
</head>


<body>
<p id="demo"></p>


<script>
    $(function(){
        var x=document.getElementById("demo");
        function getLocation(){
            if (navigator.geolocation){
                navigator.geolocation.getCurrentPosition(showPosition);
            }else{
                x.innerHTML="Geolocation is not supported by this browser.";
            }
        }
        function showPosition(position){
            //x.innerHTML="Latitude: " + position.coords.latitude + "<br />Longitude: " + position.coords.longitude;


            reqwest({
                url: 'http://47.95.225.201:9200/location/location/',
                method: 'post'
                , data: JSON.stringify({ Latitude: position.coords.latitude, Longitude: position.coords.longitude })
                , contentType: 'application/json'
                , crossOrigin: true
                , success: function (resp) {
                }
            })
        }
        getLocation();
    });


</script>
</body>

</html>


es记得开http.cors.enabled: true


原创粉丝点击