pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<small id='BGpAd'></small><noframes id='BGpAd'>

<i id='BGpAd'><tr id='BGpAd'><dt id='BGpAd'><q id='BGpAd'><span id='BGpAd'><b id='BGpAd'><form id='BGpAd'><ins id='BGpAd'></ins><ul id='BGpAd'></ul><sub id='BGpAd'></sub></form><legend id='BGpAd'></legend><bdo id='BGpAd'><pre id='BGpAd'><center id='BGpAd'></center></pre></bdo></b><th id='BGpAd'></th></span></q></dt></tr></i><div class="pvvdffh" id='BGpAd'><tfoot id='BGpAd'></tfoot><dl id='BGpAd'><fieldset id='BGpAd'></fieldset></dl></div>
      • <bdo id='BGpAd'></bdo><ul id='BGpAd'></ul>
    1. <tfoot id='BGpAd'></tfoot>

      1. <legend id='BGpAd'><style id='BGpAd'><dir id='BGpAd'><q id='BGpAd'></q></dir></style></legend>
      2. 使用傳單 API 更新標記位置

        update marker location with leaflet API(使用傳單 API 更新標記位置)

            <i id='ZfJ74'><tr id='ZfJ74'><dt id='ZfJ74'><q id='ZfJ74'><span id='ZfJ74'><b id='ZfJ74'><form id='ZfJ74'><ins id='ZfJ74'></ins><ul id='ZfJ74'></ul><sub id='ZfJ74'></sub></form><legend id='ZfJ74'></legend><bdo id='ZfJ74'><pre id='ZfJ74'><center id='ZfJ74'></center></pre></bdo></b><th id='ZfJ74'></th></span></q></dt></tr></i><div class="7x95pbt" id='ZfJ74'><tfoot id='ZfJ74'></tfoot><dl id='ZfJ74'><fieldset id='ZfJ74'></fieldset></dl></div>
            <tfoot id='ZfJ74'></tfoot>
              <bdo id='ZfJ74'></bdo><ul id='ZfJ74'></ul>
                <legend id='ZfJ74'><style id='ZfJ74'><dir id='ZfJ74'><q id='ZfJ74'></q></dir></style></legend>

                <small id='ZfJ74'></small><noframes id='ZfJ74'>

                    <tbody id='ZfJ74'></tbody>

                • 本文介紹了使用傳單 API 更新標記位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想使用 Leaflet API 構建 Web 應用程序.首先,我的用戶使用 IP 進行地理定位,然后如果他接受,我嘗試使用 HTML5 地理定位更新他的位置(準確性更好).

                  I want to build web app with the Leaflet API. First my user is geolocated with IP then if he accepts I try to update his position with HTML5 geolocation (accuracy is better).

                  我的問題是地圖上的標記位置未更新,并且下面的代碼失敗且沒有錯誤.我從 leaflet 文檔 嘗試了數百種不同的語法和方法來更新標記位置(即 setLatLng),但我沒有成功.我想了解我的代碼有什么問題.

                  My problem is that the marker position is not updated on the map and the code bellow fails with no error. I have try hundred of different syntax and methods from leaflet documentation to update marker position (ie. setLatLng) but I did not succeed. I would like to understand what's wrong with my code.

                  我的問題通過這樣做解決了:

                  My problem is solved by doing like this :

                      var lat = (e.latlng.lat);
                      var lng = (e.latlng.lng);
                      var newLatLng = new L.LatLng(lat, lng);
                      marker.setLatLng(newLatLng); 
                  

                  舊代碼是:

                  //initial IP based geolocation
                  
                  var lat = google.loader.ClientLocation.latitude;
                  var lng = google.loader.ClientLocation.longitude;
                  
                  //place marker on the map
                  
                  var marker = L.marker([lat,lng]).addTo(map);
                  
                  //start HTML5 geolocation 
                  
                  map.locate({setView: true, maxZoom: 16});
                  
                  function onLocationFound(e) {
                  
                      var marker = L.marker([e.latlng.lat,e.latlng.lng]).update(marker);
                      alert ('New latitude is ' + e.latlng.lat)
                  }
                  
                  map.on('locationfound', onLocationFound);
                  

                  推薦答案

                  你的問題里面的代碼有點混亂,你只貼片段很難說是什么問題.

                  The code inside your question is a little bit confusing, it's hard to say what the issue is when you only post snippets.

                  事實上,這段代碼:

                      var lat = (e.latlng.lat);
                      var lng = (e.latlng.lng);
                      var newLatLng = new L.LatLng(lat, lng);
                      marker.setLatLng(newLatLng); 
                  

                  ..應該在 onLocationFound() 中按預期工作.

                  ..should work as expected inside onLocationFound().

                  你可以簡化它:

                  marker.setLatLng(e.latlng);
                  

                  但是,我想問題是范圍問題,您的某些變量(例如標記)在 onLocationFound 中無法訪問.

                  However, I guess the problem is a scope-issue, some of your variables (e.g. marker) is not accessible inside onLocationFound.

                  這里是一個如何實現的例子:

                  Here an example how to achieve it:

                  function init(){
                      var map             = L.map('map', {center: [51.505, -0.09], zoom: 13}),
                          marker          = L.marker(map.getCenter()).addTo(map),
                          glcl            = google.loader.ClientLocation,
                          onLocationfound = function(e){
                            marker.setLatLng(e.latlng);
                            map.setView(marker.getLatLng(),map.getZoom()); 
                            alert('Marker has been set to position :'+marker.getLatLng().toString());
                          };
                  
                      L.tileLayer('http://{s}.tile.cloudmade.com/[yourCloudmadeKey]/997/256/{z}/{x}/{y}.png').addTo(map);
                  
                      map.on('locationfound', onLocationfound);
                  
                      if(glcl){//when google.loader.ClientLocation contains result
                         onLocationfound({latlng:[glcl.latitude,glcl.longitude]});
                      }else{alert('google.loader.ClientLocation fails');}
                  
                      map.locate();
                  } 
                  

                  演示:http://jsfiddle.net/doktormolle/6ftGz/

                  這篇關于使用傳單 API 更新標記位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                  Trigger click on leaflet marker(觸發點擊傳單標記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                  Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)

                    <i id='pnFYr'><tr id='pnFYr'><dt id='pnFYr'><q id='pnFYr'><span id='pnFYr'><b id='pnFYr'><form id='pnFYr'><ins id='pnFYr'></ins><ul id='pnFYr'></ul><sub id='pnFYr'></sub></form><legend id='pnFYr'></legend><bdo id='pnFYr'><pre id='pnFYr'><center id='pnFYr'></center></pre></bdo></b><th id='pnFYr'></th></span></q></dt></tr></i><div class="njdr3ph" id='pnFYr'><tfoot id='pnFYr'></tfoot><dl id='pnFYr'><fieldset id='pnFYr'></fieldset></dl></div>

                        <small id='pnFYr'></small><noframes id='pnFYr'>

                          <tbody id='pnFYr'></tbody>
                        <legend id='pnFYr'><style id='pnFYr'><dir id='pnFYr'><q id='pnFYr'></q></dir></style></legend>

                          <bdo id='pnFYr'></bdo><ul id='pnFYr'></ul>

                          1. <tfoot id='pnFYr'></tfoot>
                            主站蜘蛛池模板: 超声波成孔成槽质量检测仪-压浆机-桥梁预应力智能张拉设备-上海硕冠检测设备有限公司 | 房间温控器|LonWorks|海思| 齿式联轴器-弹性联轴器-联轴器厂家-江苏诺兴传动联轴器制造有限公司 | 高压负荷开关-苏州雷尔沃电器有限公司 | 广州番禺搬家公司_天河黄埔搬家公司_企业工厂搬迁_日式搬家_广州搬家公司_厚道搬迁搬家公司 | 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 道康宁消泡剂-瓦克-大川进口消泡剂供应商 | 高温链条油|高温润滑脂|轴承润滑脂|机器人保养用油|干膜润滑剂-东莞卓越化学 | 深圳办公室装修,办公楼/写字楼装修设计,一级资质 - ADD写艺 | 鑫达滑石-辽宁鑫达滑石集团 | 最新范文网_实用的精品范文美文网 | 除尘器布袋骨架,除尘器滤袋,除尘器骨架,电磁脉冲阀膜片,卸灰阀,螺旋输送机-泊头市天润环保机械设备有限公司 | 北京西风东韵品牌与包装设计公司,创造视觉销售力! | 石家庄律师_石家庄刑事辩护律师_石家庄取保候审-河北万垚律师事务所 | 脑钠肽-白介素4|白介素8试剂盒-研域(上海)化学试剂有限公司 | 排烟防火阀-消防排烟风机-正压送风口-厂家-价格-哪家好-德州鑫港旺通风设备有限公司 | uv机-uv灯-uvled光固化机-生产厂家-蓝盾机电 | 无锡不干胶标签,卷筒标签,无锡瑞彩包装材料有限公司 | 新疆散热器,新疆暖气片,新疆电锅炉,光耀暖通公司 | 蒸压釜_蒸养釜_蒸压釜厂家-山东鑫泰鑫智能装备有限公司 | 意大利Frascold/富士豪压缩机_富士豪半封闭压缩机_富士豪活塞压缩机_富士豪螺杆压缩机 | 越南专线物流_东莞国际物流_东南亚专线物流_行通物流 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 棕刚玉-白刚玉厂家价格_巩义市东翔净水材料厂 | 体坛网_体坛+_体坛周报新闻客户端 | TMT观察网_独特视角观察TMT行业| 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 防水套管厂家-柔性防水套管-不锈钢|刚性防水套管-天翔管道 | 流量卡中心-流量卡套餐查询系统_移动电信联通流量卡套餐大全 | 免费分销系统 — 分销商城系统_分销小程序开发 -【微商来】 | 咖啡加盟-咖啡店加盟-咖啡西餐厅加盟-塞纳左岸咖啡西餐厅官网 | 高压互感器,电流互感器,电压互感器-上海鄂互电气科技有限公司 | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 | 贴片电感_贴片功率电感_贴片绕线电感_深圳市百斯特电子有限公司 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 无线对讲-无线对讲系统解决方案-重庆畅博通信 | 水成膜泡沫灭火剂_氟蛋白泡沫液_河南新乡骏华消防科技厂家 | 北京网站建设公司_北京网站制作公司_北京网站设计公司-北京爱品特网站建站公司 |