UI5-技术篇-Hybrid App-2-Geolocation位置定位
2024-10-21 12:50:31
在SAP WEB IDE简单测试基于HTML5自带的定位功能,相关步骤如下:
1.VIEW代码
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="zrico_appnszrico_pn_scan.controller.GeoLocation" xmlns:html="http://www.w3.org/1999/xhtml">
<App>
<pages>
<Page
title="{i18n>GeoLocation.Page.title}"
showNavButton="true"
navButtonPress="onNavBack"
backgroundDesign="Transparent">
<content>
<Button id="BTGeoLoc" text="{i18n>GeoLocation.Button.text}" type="Emphasized" press="onGeoLocButton" > </Button>
</content>
</Page>
</pages>
</App>
</mvc:View>
2.Controller代码
jQuery.sap.includeScript("/webapp/src/src/cordova.js");
sap.ui.define([
"zrico_appnszrico_pn_scan/controller/BaseController",
"sap/ui/core/mvc/Controller",
"sap/ui/core/UIComponent",
"sap/m/MessageBox",
"sap/ui/Device"
], function(BaseController,Controller,UIComponent,MessageBox,Device) {
"use strict"; return BaseController.extend("zrico_appnszrico_pn_scan.controller.GeoLocation", { onGeoLocButton: function () {
//document.addEventListener("deviceready", this.onDeviceReady, false);
navigator.geolocation.getCurrentPosition(this.onSuccess2, this.onError2, { maximumAge: 3000, timeout: 30000}) //精度设置 enableHighAccuracy: true
}, onSuccess2:function(position){
MessageBox.show(
"Latitude: " + position.coords.latitude + "\n" +
"Longitude:" + position.coords.longitude + "\n" +
"Altitude: " + position.coords.altitude + "\n" +
"Accuracy: " + position.coords.accuracy + "\n" +
"Altitude Accuracy: " + position.coords.altitudeAccuracy + "\n" +
"Heading: " + position.coords.heading + "\n" +
"Speed: " + position.coords.speed + "\n" +
"Timestamp:" + position.timestamp + "\n");
}, onError2:function(error){
MessageBox.show(
"code: " + error.code + "\n" +
"message: " + error.message + "\n");
} }); });
3.SAP WEB IDE 测试
chrome谷歌浏览器执行过程中报错,应该是网络原因需要翻墙。
在IE浏览器中测试,显示正常。
最新文章
- ThinkPHP跨控制器调用方法
- linux装JDK
- cacti监控mysql
- 关于HTML+CSS设置图片居中的方法
- StringUtil
- hdu1241 Oil Deposits
- UVa 10817 Headmaster&#39;s Headache (状压DP+记忆化搜索)
- 用shell查找某个目录下最大文件
- c++实现dll注入其它进程
- Charles Proxy 4.1.2 破解版
- MySQL Windows版安装详解
- for循环&;len函数和range函数的运用
- MySQL GTID 主从复制错误修复方法
- requests 请求几个接口 出现’您的账户在其它设备使用过,为保障安全,需重新登入才能在本设备使用‘
- ServiceWorker和WebWorker
- Spring配置文件引入xml文件: <;import resource="; "; />;标签使用总结
- 前端构建工具Gulp使用总结
- Linux addr2line命令
- 2018年秋PTA乙级回顾
- PHP和JS中全局变量和局部变量