浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。

文档全面上新

更科技的视觉体验,更高效的页面结构,快前往体验吧!

体验新版

定位组件

利用定位组件开发者可以在自己的页面嵌入webapp百度地图样式的定位模块,且通过定位事件获取到定位点的经纬度坐标。

嵌入定位模块的代码片如下:

<lbs-geo city="北京" enable-modified="false"></lbs-geo>

运行效果如下: XX 利用定位组件获取定位点经纬度坐标代码段如下:

<lbs-geo id="geo" city="北京" enable-modified="false"></lbs-geo>
<script>
 // 先获取元素
 var mapElement = document.getElementById('geo');
 mapElement.addEventListener("geostart",function(evt){ //注册事件
 console.log(evt.detail);
 })
</script>
利用定位坐标获取定位经纬度坐标需要三步:

1.	设置定位标签时首先设置标签的id属性;

2.	根据id标签属性获取定位控件

3.	给定位控件注册定位事件

完整代码请参考:
<syntaxhighlight lang="html4strict" line start="100" enclose="div">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>定位组件</title>
<script src="http://api.map.baidu.com/components?ak=CA4de4f8d8e3c3891eb39a78f8343cd4&v=1.0">
</script>
</head>
<body>
    <!—定位组件-->
    <lbs-geo id="geo" city="北京" enable-modified="false"></lbs-geo>
    <script>
    // 先获取元素
    var mapElement = document.getElementById('geo');
	mapElement.addEventListener("geostart",function(evt){ //注册事件
	console.log(evt.detail);
	}) 
</script>
</body>
</html>


</syntaxhighlight>
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消