如何使用传单定位定位用户? [英] How to locate user with leaflet locate?

查看:25
本文介绍了如何使用传单定位定位用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试定位用户并使用传单将地图设置到此位置:

I'm trying to locate a user and set the map to this position with leaflet:

    <script>
    var map;

    function initMap(){
        map = new L.Map('map',{zoomControl : false});
        var osmUrl = 'http://{s}.tile.openstreetmap.org/mapnik_tiles/{z}/{x}/{y}.png',
            osmAttribution = 'Map data &copy; 2012 OpenStreetMap contributors',
            osm = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
        map.setView(new L.LatLng(51.930156,7.189230), 7).addLayer(osm);
    }

    function locateUser(){
        map.locate({setView : true});
    }
</script>

在执行浏览器请求许可,但没有任何反应?我的代码有什么问题?

On execute the browser ask for permission, but then nothing happens? What's wrong with my code?

推荐答案

您的地图变量范围存在问题.我在这里发布了一个修复您的代码的示例:http://jsfiddle.net/XwbsU/3/

You have an issue with the scope of your map variable. I have posted an example that fixes your code here: http://jsfiddle.net/XwbsU/3/

当您点击找到我!"时,您应该会收到浏览器地理位置弹出窗口.

You should receive the browser geolocation popup when you click 'Find me!'.

希望对你有所帮助.

这篇关于如何使用传单定位定位用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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