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

相关文章

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框

HTML img标签和超链接标签详细介绍

《HTMLimg标签和超链接标签详细介绍》:本文主要介绍了HTML中img标签的使用,包括src属性(指定图片路径)、相对/绝对路径区别、alt替代文本、title提示、宽高控制及边框设置等,详细内容请阅读本文,希望能对你有所帮助... 目录img 标签src 属性alt 属性title 属性width/h

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

HTML5 中的<button>标签用法和特征

《HTML5中的<button>标签用法和特征》在HTML5中,button标签用于定义一个可点击的按钮,它是创建交互式网页的重要元素之一,本文将深入解析HTML5中的button标签,详细介绍其属... 目录引言<button> 标签的基本用法<button> 标签的属性typevaluedisabled

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F