在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浏览器中测试,显示正常。

 

最新文章

  1. ThinkPHP跨控制器调用方法
  2. linux装JDK
  3. cacti监控mysql
  4. 关于HTML+CSS设置图片居中的方法
  5. StringUtil
  6. hdu1241 Oil Deposits
  7. UVa 10817 Headmaster&#39;s Headache (状压DP+记忆化搜索)
  8. 用shell查找某个目录下最大文件
  9. c++实现dll注入其它进程
  10. Charles Proxy 4.1.2 破解版
  11. MySQL Windows版安装详解
  12. for循环&amp;len函数和range函数的运用
  13. MySQL GTID 主从复制错误修复方法
  14. requests 请求几个接口 出现’您的账户在其它设备使用过,为保障安全,需重新登入才能在本设备使用‘
  15. ServiceWorker和WebWorker
  16. Spring配置文件引入xml文件: &lt;import resource=&quot; &quot; /&gt;标签使用总结
  17. 前端构建工具Gulp使用总结
  18. Linux addr2line命令
  19. 2018年秋PTA乙级回顾
  20. PHP和JS中全局变量和局部变量

热门文章

  1. Docker for mac开启docker api调用
  2. 浏览器渲染基本原理(二):JS引擎的工作方式
  3. PostMan Request Export
  4. Jmeter之测试计划
  5. 史上最全的 DB2 错误代码大全
  6. Base64(2)
  7. js 模糊搜索
  8. SVN限制普通用户删除文件及提交时必须填写log日志
  9. csp联考T1
  10. win10 双网卡设置内网和外网同时访问