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

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

问题描述

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

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天全站免登陆