简体   繁体   English

phonegap cordova地理位置未在电话上显示

[英]phonegap cordova gelocation not showing out on phone

 var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; var myLatlng = new google.maps.LatLng(37.3000, -120.4833); var mapOptions = { center: myLatlng, zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map"), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, draggable: true, animation: google.maps.Animation.DROP }); navigator.geolocation.getCurrentPosition(function(pos) { map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)); var myLocation = new google.maps.Marker({ position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude), map: map, title: "My Location" }); }); 
 <html lang="en"> <head> <meta charset="UTF-8"> <title>Geo Location</title> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map { height: 100% } </style> <script type="text/javascript" src="cordova.js"></script> <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyB1oJGDZP2lM3c1dnPBmAbPBOb_Rh4u8n0&sensor=true"></script> <script type="text/javascript" src="js/index.js"></script> </head> <body> asd <div id="map"></div> </body> </html> 

When I run this two file the google map is not appearing in my phone I dont know why but when run this in the web browser it work I had also install the cordova geolocation plugin and add permission but still unable to get it work can anyone of you help me out? 当我运行这两个文件时,谷歌地图没有出现在我的手机中,我不知道为什么,但是当在网络浏览器中运行它时,我也安装了cordova geolocation插件并添加了权限,但仍然无法使它工作。你帮我吗?

@user3711175, you have several issues. @ user3711175,您有几个问题。 @Joerg is correct. @Joerg是正确的。 You will need to use the whitelist system. 您将需要使用whitelist系统。 You have two (2) issues. 您有两(2)个问题。

UPDATE - 2015-12-23 : I misread the code. 更新-2015-12-23 :我误读了代码。 #1 does not apply #1不适用

###1. ### 1。 You are using the this in the wrong context in your 您在错误的上下文中使用了this

document.addEventListener('deviceready', this.onDeviceReady, false);

You want to write app.onDeviceReady , like this: 您要这样编写app.onDeviceReady

 document.addEventListener('deviceready', app.onDeviceReady, false); 

When your EventListener finally fires, it is no longer in the context of you app Object. 当您的EventListener最终触发时,它不再位于您的app对象的上下文中。 It is now global. 现在是全球性的。 For details, See this SO post 有关详细信息,请参见此SO帖子

2. You need to apply the whitelist system 2.您需要应用whitelist系统

This whitelist worksheet should help. 白名单工作表应有所帮助。
HOW TO apply the Cordova/Phonegap the whitelist system 如何将Cordova / Phonegap应用到白名单系统

The following need to be added to the whitelist for Google map production . 需要将以下内容添加到whitelist以进行Google地图制作

The following domains are required for Google Maps. Google地图需要以下域。

  • maps.googleapis.com maps.googleapis.com
  • mt0.googleapis.com mt1.googleapis.com mt0.googleapis.com mt1.googleapis.com
  • fonts.googleapis.com fonts.googleapis.com
  • csi.gstatic.com csi.gstatic.com
  • maps.gstatic.com maps.gstatic.com

Wild cards ( * ) are available. 可以使用通配符( * )。 Read the documentation. 阅读文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM