HTML5培训第15节课堂笔记(HTML5+maps,geolocation)

2024-09-02 17:48

本文主要是介绍HTML5培训第15节课堂笔记(HTML5+maps,geolocation),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

HTML5培训第15节课堂笔记

1.地理信息定位:

window.οnlοad=function(){

        mui.plusReady(function(){

           plus.geolocation.getCurrentPosition(function(p){

               latitude=p.coords.latitude;

               longitude=p.coords.longitude;

               varaddress=p.addresses;

           },function(e){

               console.log(e.message);

           },{

               provider:"baidu"

              

           });

        });

 

 

//监听

           varwatchID=

           plus.geolocation.watchPosition(function(){},function(),{});

           plus.geolocation.clearWatch(watchID);

 

 

 

2.打开baidu地图进行导航

var src=new plus.maps.Point(latitude,longitude);

               vardst=new plus.maps.Point("31.0242342","109.242432432");

               plus.maps.openSysMap(dst,"都江堰xx地",src);

 

 

mui.openWindow({

                  url:"showMap.html",

                  id:"showMap.html",

                  extras:{lat:latitude,longi:longitude},

                  show:{

                      autoShow:false

                  }

               });

 

 

3.跨页面拿值:cur=plus.webview.currentWebview();

              latitude=cur.lati;

              longitude=cur.longi;

 

 

4.显示地图:window.οnlοad=function(){

           mui.plusReady(function(){

              cur=plus.webview.currentWebview();

              latitude=cur.lati;

              longitude=cur.longi;

              pcenter=newplus.maps.Point(longitude,latitude);

              map=newplus.maps.Map("mymap");

              map.centerAndZoom(pcenter,16);

             

              plus.nativeUI.closeWaiting();

              cur.show();

             

           })

       };

 

 

mymap指的是相应地图区域div的id值

 

标记点的作法:

function createMarker()

       {

           var marker=new plus.maps.Marker(pcenter);

           marker.setIcon("imgs/map.jpg");

           marker.setLabel("成都东软学院 C7");

           var bubble=newplus.maps.Bubble("我在 成都东软学院 C7附近<br/>电话:028-888888");

           marker.setBubble(bubble);

           map.addOverlay(marker);

          

       }

 

其他方法: map.showUserLocation(true);
map.getUserLocation(function(p){});
plus.maps.Circle(pcenter,0.5);

 



完整代码:

getPlus.html

 

<!DOCTYPE html>

<html>

<head>

    <metacharset="UTF-8">

    <metaname="viewport"content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

   <title></title>

    <style>

       .mui-content{

           margin:0 auto;

           text-align: center;

       }

       .mui-content button{

           width:70%;

           margin-top:80px;

       }

    </style>

    <scriptsrc="js/mui.min.js"></script>

    <linkhref="css/mui.min.css" rel="stylesheet"/>

    <scripttype="text/javascript" charset="UTF-8">

      mui.init();

    </script>

</head>

<body>

<header class="mui-bar mui-bar-nav">

    <aclass="mui-action-back mui-icon mui-icon-left-navmui-pull-left"></a>

    <h1 class="mui-title">标题</h1>

</header>

<div class="mui-content">

<button class="mui-btn-primary" id="butnOpenBaidu"/>打开百度</button>

<button class="mui-btn-primary" id="butnOpenInner"/>使用内置地图</button>

 

</div>

 

    <script>

    var latitude;//纬度

    var longitude;//经度

    window.οnlοad=function(){

       mui.plusReady(function(){

           plus.geolocation.getCurrentPosition(function(p){//成功回调函数

              latitude=p.coords.latitude;

              longitude=p.coords.longitude;

              varaddress=p.addresses;

           },function(e){//失败回调函数

              console.log(e.message);

           },{//参数配置

              provider:"bdidu"//百度

           });

           //监听

           varwatchID=plus.geolocation.watchPosition(function(){

             

           },

           function(){

             

           },

           {

             

           });

           //停止监听

           plus.geolocation.clearWatch(watchID);

          

       })

      

       document.getElementById("butnOpenBaidu").addEventListener("tap",function(){

           var src=newplus.maps.Point(longitude,latitude);//起点

           var dst=newplus.maps.Point("109.5555","31.5885");

          

           plus.maps.openSysMap(dst,"都江堰",src);//打开已经有的地图

       })

      

       document.getElementById("butnOpenInner").addEventListener("tap",function(){

           mui.openWindow({

              url:"showMap.html",

              id:"showMap.html",

              extras:{

               latitude:latitude,

                  longitude:longitude

              },

              show:{

                  autoShow:false

              }

              

           })

       },false);

      

      

    }

    </script>

</body>

</html>

 

 

 

showMap.html

<!DOCTYPE html>

<html>

<head>

    <metacharset="UTF-8">

    <metaname="viewport"content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

   <title></title>

    <scriptsrc="js/mui.min.js"></script>

    <linkhref="css/mui.min.css" rel="stylesheet"/>

    <style>

       #map{

           height:800px;

       }

    </style>

    <scripttype="text/javascript" charset="UTF-8">

      mui.init();

    </script>

</head>

<body>

    <!--使用内置地图-->

    <headerclass="mui-bar mui-bar-nav">

        <h1 class="mui-title">地图显示</h1>

    </header>

    <div class="mui-content">

       <!--装地图区域-->

       <divid="map">

          

       </div>

    </div>

</body>

<script>

var cur;

var latitude,longitude;

var pcenter;//中心点

var map;

    window.οnlοad=function(){

       mui.plusReady(function(){

           cur=plus.webview.currentWebview();

                 latitude=cur.latitude;

                  longitude=cur.longitude;

                  pcenter=newplus.maps.Point(longitude,latitude);

                  map=newplus.maps.Map("map");//地图控件

                  map.centerAndZoom(pcenter,16);//把地图定位到中心,以中心点作为缩放

                 createMarker();

                  plus.nativeUI.closeWaiting();//关闭进度条

                  //窗口显示

                  cur.show();

       })

    };

    functioncreateMarker(){

       var marker=newplus.maps.Marker(pcenter);

       marker.setIcon("images/map.jpg");//图标

       marker.setLabel("我在成都东软学院附近");

       //气泡

       var bubble=newplus.maps.Bubble("我在成都东软学院");//一点跳出提示文字支持html标识

       marker.setBubble(bubble);

       map.addOverlay(marker)//在地图上做一些特殊的东西

    }

    //map.showUserLocation(true);

    //map.getUserLocation(function(p){});//获得当前用户的位置

   

    //plus.maps.Circle(pcenter,0.5);

</script>

</html>

 

 

地图插件配置

Mainifest.json  sdk配置

 

获取key参考:

http://ask.dcloud.net.cn/article/29


 

这篇关于HTML5培训第15节课堂笔记(HTML5+maps,geolocation)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1130642

相关文章

HTML5中的Microdata与历史记录管理详解

《HTML5中的Microdata与历史记录管理详解》Microdata作为HTML5新增的一个特性,它允许开发者在HTML文档中添加更多的语义信息,以便于搜索引擎和浏览器更好地理解页面内容,本文将探... 目录html5中的Mijscrodata与历史记录管理背景简介html5中的Microdata使用M

html5的响应式布局的方法示例详解

《html5的响应式布局的方法示例详解》:本文主要介绍了HTML5中使用媒体查询和Flexbox进行响应式布局的方法,简要介绍了CSSGrid布局的基础知识和如何实现自动换行的网格布局,详细内容请阅读本文,希望能对你有所帮助... 一 使用媒体查询响应式布局        使用的参数@media这是常用的

HTML5表格语法格式详解

《HTML5表格语法格式详解》在HTML语法中,表格主要通过table、tr和td3个标签构成,本文通过实例代码讲解HTML5表格语法格式,感兴趣的朋友一起看看吧... 目录一、表格1.表格语法格式2.表格属性 3.例子二、不规则表格1.跨行2.跨列3.例子一、表格在html语法中,表格主要通过< tab

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

前端下载文件时如何后端返回的文件流一些常见方法

《前端下载文件时如何后端返回的文件流一些常见方法》:本文主要介绍前端下载文件时如何后端返回的文件流一些常见方法,包括使用Blob和URL.createObjectURL创建下载链接,以及处理带有C... 目录1. 使用 Blob 和 URL.createObjectURL 创建下载链接例子:使用 Blob

Vuex Actions多参数传递的解决方案

《VuexActions多参数传递的解决方案》在Vuex中,actions的设计默认只支持单个参数传递,这有时会限制我们的使用场景,下面我将详细介绍几种处理多参数传递的解决方案,从基础到高级,... 目录一、对象封装法(推荐)二、参数解构法三、柯里化函数法四、Payload 工厂函数五、TypeScript

利用Python快速搭建Markdown笔记发布系统

《利用Python快速搭建Markdown笔记发布系统》这篇文章主要为大家详细介绍了使用Python生态的成熟工具,在30分钟内搭建一个支持Markdown渲染、分类标签、全文搜索的私有化知识发布系统... 目录引言:为什么要自建知识博客一、技术选型:极简主义开发栈二、系统架构设计三、核心代码实现(分步解析

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo