使用hbuilder打包时,调用地图和相机
<template>
<div class="comCon">
<!-- 你是头部区域的内容 -->
<headback class="header" @back='back'>
<span>地图</span>
</headback>
<!-- 你是内容部分 -->
<div class="bodyCont">
<!-- 内容区 -->
<div class="const-me">
<!-- 个人中心部分-->
<div class="person-content">
获取用户的当前位置信息<br/>
<button @click="getUserLocation()">获取位置</button>
<button @click="getCurrentCenter()">获取中心位置</button>
<div id="map">地图加载中...</div>
</div>
<div>
<button @click="scanFile()">浏览文件</button>
</div>
</div>
</div>
</div>
</template> <script>
import {mixins} from 'assets/js/mixins'
import picker from 'base/picker/picker'
import headback from 'base/head/head-back'
import i18n from "assets/js/vi18n/i18n.js" export default {
mixins:[mixins],
i18n,
components: {
picker,
headback
},
data(){
return {
}
},
mounted(){
// H5 plus事件处理
if(window.plus){
console.log(1);
this.plusReady();
console.log(1.1);
}else{
console.log(2);
document.addEventListener("plusready",this.plusReady(),false);
console.log(2.1);
}
},
methods: {
scanFile(){
var vm=this;
var fileURL='http://report.zkteco.com/file/globalservice/pdf/%E9%9B%86%E8%AE%AD%E8%90%A51_%E7%9C%8B%E5%9B%BE%E7%8E%8B_1526894807867.pdf';
console.log(1001);
if(fileURL !=''){
plus.nativeUI.actionSheet({
cancel: 'Cancel',
buttons: [{
title: 'Download the file'
}, {
title: 'OK'
}]
}, function(e) {
var i = e.index;
if(i == 1) {
}else if(i == 2) {
console.log(1002);
plus.nativeUI.showWaiting('');
var localURL = vm.getLocalImg(fileURL);
vm.openfiles(localURL);/*打开文件*/
}else{
}
});
return false;
}
console.log(1003);
},
/*检测文件是否存在并打开*/
openfiles (localURL) {
let vm=this;
console.log(1004);
plus.io.resolveLocalFileSystemURL(plus.io.convertAbsoluteFileSystem(localURL), function(entry) {
plus.nativeUI.closeWaiting();
// localURL = plus.io.convertLocalFileSystemURL(localURL);
plus.runtime.openFile( plus.io.convertAbsoluteFileSystem(localURL), null, function () {
plus.nativeUI.alert( 'The file could not be opened', function(){}, official, 'OK');
});
}, function(e) {
setTimeout(function() {
console.log(1005);
vm.openfiles(localURL);/*等待图片下载完成*/
},300);
});
},
//获取缓存图片
getLocalImg(source){
let vm=this;
if(source == null || source == '' || source == 'undefined'){
return '';
}else if(source.indexOf('../public')==0){
return source;
} source = source.indexOf('http')<0? (webRoot + source) : source; var lastName = source.split('/').pop();
var localName = "_downloads/" + lastName;
plus.io.resolveLocalFileSystemURL(localName, function(entry) {
}, function(e) {
vm.downloadSource(source,localName);
});
return plus.io.convertLocalFileSystemURL(localName);
},
/*下载图片到缓存*/
downloadSource (source,localName) {
var regChinese = /[\u4E00-\u9FA5]/g;
var tmpLoadUrl = source.replace(regChinese, 'chineseRemoveAfter');
if (tmpLoadUrl.indexOf('chineseRemoveAfter') != -1) {
source = encodeURI(source);
}
var dtask = plus.downloader.createDownload(source,{filename:localName}, function ( d, status ) {
if ( status == 200 ) {
console.log(d.filename);
}else{
console.log('error');
}
});
dtask.start();
},
plusReady(){
console.log(2.12);
var point = new plus.maps.Point(116.347496,39.970191);
plus.maps.Map.reverseGeocode(point,{},function(event){
var address = event.address; // 转换后的地理位置
var point = event.coord; // 转换后的坐标信息
var coordType = event.coordType; // 转换后的坐标系类型
alert("Address:"+address);
},function(e){
alert("Failed:"+JSON.stringify(e));
});
console.log(1.12);
},
// 获取当前地图显示的地图中心点位置
getCurrentCenter(){
map.getCurrentCenter( function ( state, point ){
if( 0 == state ){
alert( JSON.stringify(point) );
}else{
alert( "Failed!" );
}
} );
},
getUserLocation(){
// 获取用户的当前位置信息
map.getUserLocation( function ( state, point ){
if( 0 == state ){
alert( JSON.stringify(point) );
}else{
alert( "Failed!" );
}
} );
},
back(){
this.$router.go(-1);
},
},
watch: { }
}
</script> <style scoped lang="stylus" rel="stylesheet/stylus">
@import '~assets/stylus/veriable.styl'
.comCon
position fixed
top 0
left 0
right 0
bottom 0
z-index 16
background $color-background-all
.const-me
.person-content
background #ffffff
div
min-height 18.75rem </style>
<template>
<div class="comCon">
<!-- 你是头部区域的内容 -->
<headback class="header" @back='back'>
<span>相机</span>
</headback>
<!-- 你是内容部分 -->
<div class="bodyCont">
<!-- 内容区 -->
<div class="const-me">
<!-- 个人中心部分-->
<div class="person-content">
<!-- <div @click="onPlusReady">Camera : 摄像头对象</div> -->
<!-- <div @click="captureImage1">Camera : 拍照1</div> -->
<div @click="captureImage">Camera : 拍照</div>
<div @click="videoCapture">Camera : 摄像头</div>
</div>
</div>
</div>
</div>
</template> <script>
import {mixins} from 'assets/js/mixins'
import picker from 'base/picker/picker'
import headback from 'base/head/head-back'
import i18n from "assets/js/vi18n/i18n.js" export default {
mixins:[mixins],
i18n,
components: {
picker,
headback
},
data(){
return {
probeType:3,
totalHeight:[],
pos:0,
currentIndex:1,
showFooter:false,
data:[],
scrollEndx:true,
person:[
{
text:"edit_password",
icon:'iconfont icon-edit',
path:'editPassword'
},
{
text:"personal_message",
icon:'iconfont icon-wxbzhanghu',
path:'personInfo'
},
{
text:"pay_attention_to_people",
icon:'iconfont icon-group',
path:'attention'
}
]
}
},
created () {
this.keydata=[];
},
methods: {
onPlusReady(){
var cmr = plus.camera.getCamera();
},
captureImage(){
var cmr = plus.camera.getCamera();
var res = cmr.supportedImageResolutions[0];
var fmt = cmr.supportedImageFormats[0];
console.log("Resolution: "+res+", Format: "+fmt);
var path='storage/emulated/0/DCIM/Camera/';
///private/var/root/Media/DCIM
var ua = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(ua)) {
path='private/var/root/Media/DCIM/';
} else if (/android/.test(ua)) {
path='storage/emulated/0/DCIM/Camera/';
}
cmr.captureImage(function(path){
plus.gallery.save(path);
})
// cmr.captureImage( function( path ){
// alert( "Capture image success: " + path );
// },
// function( error ) {
// alert( "Capture image failed: " + error.message );
// },
// {resolution:res,format:fmt}
// );
},
captureImage1(){
// interface CameraOption {
// attribute String 'storage/emulated/0/DCIM/Camera/';
// },
var cmr = plus.camera.getCamera();
var res = cmr.supportedImageResolutions[0];
var fmt = cmr.supportedImageFormats[0];
console.log("Resolution: "+res+", Format: "+fmt);
cmr.captureImage( function( path ){
alert( "Capture image success: " + path );
},
function( error ) {
alert( "Capture image failed: " + error.message );
},
{resolution:res,format:fmt}
);
},
videoCapture(){
// interface CameraOption {
// attribute String '/storage/emulated/0/DCIM/Camera/';
// },
var cmr = plus.camera.getCamera();
var res = cmr.supportedVideoResolutions[0];
var fmt = cmr.supportedVideoFormats[0];
console.log("Resolution: "+res+", Format: "+fmt);
var path='/storage/emulated/0/DCIM/Camera/';
cmr.captureImage(function(path){
plus.gallery.save(path);
}),
cmr.startVideoCapture( function( path ){
alert( "Capture video success: " + path );
},
function( error ) {
alert( "Capture video failed: " + error.message );
},
{resolution:res,format:fmt}
);
},
back(){
this.$router.go(-1);
},
},
mounted(){
document.addEventListener( "plusready", onPlusReady, false );
var r = null;
},
watch: { }
}
</script> <style scoped lang="stylus" rel="stylesheet/stylus">
@import '~assets/stylus/veriable.styl'
.comCon
position fixed
top 0
left 0
right 0
bottom 0
z-index 16
background $color-background-all
.const-me
.person-content
background #ffffff
div
padding 8px
</style>
<template>
<div class="comCon">
<!-- 你是头部区域的内容 -->
<headback class="header" @back='back'>
<span>地图this</span>
</headback>
<!-- 你是内容部分 -->
<div class="bodyCont">
<!-- 内容区 -->
<div class="const-me">
<!-- 个人中心部分-->
<div class="person-content">
获取用户的当前位置信息<br/>
<button @click="getUserLocation()">获取位置</button>
<button @click="getCurrentCenter()">获取中心位置</button>
<div id="map">地图加载中...</div>
</div>
</div>
</div>
</div>
</template> <script>
import {mixins} from 'assets/js/mixins'
import picker from 'base/picker/picker'
import headback from 'base/head/head-back'
import i18n from "assets/js/vi18n/i18n.js" export default {
mixins:[mixins],
i18n,
components: {
picker,
headback
},
data(){
return {
em:null,
map:null,
}
},
mounted(){
this.getKey();
},
methods: {
// 获取当前地图显示的地图中心点位置
getCurrentCenter(){
map.getCurrentCenter( function ( state, point ){
if( 0 == state ){
alert( JSON.stringify(point) );
}else{
alert( "Failed!" );
}
} );
},
getKey(){
let vm=this;
// H5 plus事件处理
if(window.plus){
vm.plusReady();
}else{
document.addEventListener("plusready",vm.plusReady(),false);
}
// DOMContentloaded事件处理
document.addEventListener("DOMContentLoaded",function(){
em=document.getElementById("map");
vm.plusReady();
},false);
},
plusReady(){
// 确保DOM解析完成
if(!em||!window.plus||map){return};
map = new plus.maps.Map("map");
map.centerAndZoom( new plus.maps.Point(116.3977,39.906016), 12 );
},
getUserLocation(){
// 获取用户的当前位置信息
map.getUserLocation( function ( state, point ){
if( 0 == state ){
alert( JSON.stringify(point) );
}else{
alert( "Failed!" );
}
} );
},
back(){
this.$router.go(-1);
},
},
watch: { }
}
</script> <style scoped lang="stylus" rel="stylesheet/stylus">
@import '~assets/stylus/veriable.styl'
.comCon
position fixed
top 0
left 0
right 0
bottom 0
z-index 16
background $color-background-all
.const-me
.person-content
background #ffffff
div
min-height 18.75rem </style>
使用hbuilder打包时,调用地图和相机的更多相关文章
- 【原创分享·支付宝支付】HBuilder打包APP调用支付宝客户端支付
前言 最近有点空余时间,所以,就研究了一下APP支付.前面很早就搞完APP的微信支付了,但是由于时间上和应用上的情况,支付宝一直没空去研究.然后等我空了的时候,发现支付宝居然升级了支付逻辑,虽然目前还 ...
- springboot+layui实现PC端用户的增删改查 & 整合mui实现app端的自动登录和用户的上拉加载 & HBuilder打包app并在手机端下载安装
springboot整合web开发的各个组件在前面已经有详细的介绍,下面是用springboot整合layui实现了基本的增删改查. 同时在学习mui开发app,也就用mui实现了一个简单的自动登录和 ...
- android 调用地图
有时候我们需要调用地图显示一下位置,这时候可能还需要导航,导航做起来有点麻烦,如果调用第三方的是不是很简单,本文就是写这个来的: 第一种方式:android Intent调用地图应用客户端 调用百度地 ...
- ArcGIS API for Silverlight 当DataGrid选中项时,地图聚焦弹出窗口,并可以播放音频文件
原文:ArcGIS API for Silverlight 当DataGrid选中项时,地图聚焦弹出窗口,并可以播放音频文件 先看效果图,然后上代码: <UserControl x:Class= ...
- 打包时,node内存溢出问题解决方法
在使用npm run build打包时,遇到node内存溢出问题. 网上查找到的决绝方案.解决方案一: 安装increase-memory-limit插件,扩大node的内存限制 但是,这个解决方案在 ...
- 解决Hbuilder打包的apk文件按手机返回键直接退出软件
问题描述:Hbuilder打包的app如果点击手机返回键,app会直接退出,返回不了上一页. 写在公共js文件中,每个页面均引入该js,代码如下: document.addEventListener( ...
- 【方法】移动端H5如何调用相册和相机上传图片、音频、视频
在移动端上传图片方法很简单,使用HTML5中的input:file供文件上传. <一>常用属性值: 1.accept:规定文件上传来提交的文件类型,此属性只能和type:file配合使用 ...
- 刷新或关闭时调用onbeforeunload
Onunload,onbeforeunload都是在刷新或关闭时调用,可以在<script>脚本中通过window.onunload来指定或者在<body>里指定.区别在于on ...
- 利用Maven打包时,如何包含更多的资源文件
首先,来看下MAVENx项目标准的目录结构: 一般情况下,我们用到的资源文件(各种xml,properites,xsd文件等)都放在src/main/resources下面,利用maven打包时,ma ...
随机推荐
- [ML] Online learning
复习 一.Spark 流处理 使用Spark Streaming与我们操作RDD的方式很接近,处理数据流也变得简单了.使用Spark的流处理元素结合MLlib的基于SGD的在线学习能力,可以创建实时的 ...
- aws S3存储概念
S3存储(Simple Storage Service) 存储桶:存储桶是S3中用于存储对象的容器.每个对象都存储在一个存储桶中. 对象:对象是S3中存储的基本实体.对象由对象数据和元数据组成.数据部 ...
- Canal——原理架构及应用场景
Canal简介 Canal是阿里开源的一款基于Mysql数据库binlog的增量订阅和消费组件,通过它可以订阅数据库的binlog日志,然后进行一些数据消费,如数据镜像.数据异构.数据索引.缓存更新等 ...
- 转:获取windows凭证管理器明文密码
1.运行cmdkey /list查看windows保存凭证 方法1.mimikaz mimikatz vault::cred 2.利用powershell尝试获取 windows 普通凭据类型中的明文 ...
- TypeError: __init__() got an unexpected keyword argument 'serialized_options'
问题描述: TypeError: __init__() got an unexpected keyword argument 'serialized_options' File "objec ...
- VAEs(变分自编码)之keras实践
VAEs最早由“Diederik P. Kingma and Max Welling, “Auto-Encoding Variational Bayes, arXiv (2013)”和“Danilo ...
- Redis的大白话解释
Redis的官方解释可以百度,这里讲redis缓存为啥速度非常快! 这么说吧,别人问你什么是“redis”,如果你知道,你可以直接吧啦吧啦一大堆,其实这个时候你的大脑就类似redis缓存,别人问的“r ...
- Java学习笔记-网络编程
Java提供了网络编程,并且在实际中有着大量运用 网络编程 网络编程概述 网络模型 OSI参考模型 TCP/IP参考模型 网络通讯要素 IP地址 端口号 传输协议 网络参考模型 网络通讯要素 IP地址 ...
- 非常好用的vue数字滚动插件vue-countTo
参考链接:https://blog.csdn.net/gaoxin666/article/details/84635056
- CWMP开源代码研究7——cwmp移植
原创作品,转载请注明出处,严禁非法转载.如有错误,请留言! email:40879506@qq.com 声明:本系列涉及的开源程序代码学习和研究,严禁用于商业目的. 如有任何问题,欢迎和我交流.(企鹅 ...