UI5-技术篇-Hybrid App-2-Geolocation位置定位

在SAP WEB IDE简单测试基于HTML5自带的定位功能,相关步骤如下:

1.VIEW代码

 1 <mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
 2     controllerName="zrico_appnszrico_pn_scan.controller.GeoLocation" xmlns:html="http://www.w3.org/1999/xhtml">
 3     <App>
 4         <pages>
 5             <Page             
 6             title="{i18n>GeoLocation.Page.title}" 
 7             showNavButton="true" 
 8             navButtonPress="onNavBack" 
 9             backgroundDesign="Transparent">
10                 <content>
11                     <Button id="BTGeoLoc" text="{i18n>GeoLocation.Button.text}" type="Emphasized" press="onGeoLocButton" > </Button>
12                 </content>
13             </Page>
14         </pages>
15     </App>
16 </mvc:View>

 

2.Controller代码

 1 jQuery.sap.includeScript("/webapp/src/src/cordova.js");
 2 sap.ui.define([
 3     "zrico_appnszrico_pn_scan/controller/BaseController",
 4     "sap/ui/core/mvc/Controller",
 5     "sap/ui/core/UIComponent",
 6     "sap/m/MessageBox",
 7     "sap/ui/Device"
 8 ], function(BaseController,Controller,UIComponent,MessageBox,Device) {
 9     "use strict";
10 
11     return BaseController.extend("zrico_appnszrico_pn_scan.controller.GeoLocation", {
12         
13         onGeoLocButton: function () {
14             //document.addEventListener("deviceready", this.onDeviceReady, false);
15             navigator.geolocation.getCurrentPosition(this.onSuccess2, this.onError2, { maximumAge: 3000, timeout: 30000})  //精度设置 enableHighAccuracy: true 
16         },
17         
18         onSuccess2:function(position){
19               MessageBox.show(
20                   "Latitude: "          + position.coords.latitude          + "\n" +
21                   "Longitude:"          + position.coords.longitude         + "\n" +
22                   "Altitude: "          + position.coords.altitude          + "\n" +
23                   "Accuracy: "          + position.coords.accuracy          + "\n" +
24                   "Altitude Accuracy: " + position.coords.altitudeAccuracy  + "\n" +
25                   "Heading:  "          + position.coords.heading           + "\n" +
26                   "Speed:     "          + position.coords.speed             + "\n" +
27                   "Timestamp:"          + position.timestamp                + "\n");
28          },
29         
30         onError2:function(error){
31              MessageBox.show(
32                  "code: "    + error.code    + "\n" +
33                 "message: " + error.message + "\n");
34          }
35 
36     });
37 
38 });

 

3.SAP WEB IDE 测试

 chrome谷歌浏览器执行过程中报错,应该是网络原因需要翻墙。

 

 在IE浏览器中测试,显示正常。

 

转载于:https://www.cnblogs.com/ricoo/p/11338035.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值