我已经在使用phonegap开发的ios应用中插入了地理定位功能。
当我打开我的map.html页面时,设备应该在google地图上显示我的位置。现在,当我打开map.html时,我收到了使用我的gps的请求,然后出现了一条错误消息:" Google禁止将Google Maps API用于此应用程序。提供的密钥不是有效的Google API密钥,也未授权此网站上的Google Maps API Javascript v3。如果您是此应用的所有者,可以在此处找到其他信息:https://developers.google.com/maps/documentation/javascript/tutorial#api_key"
所以问题是api密钥,我已阅读文档并在网上搜索但我无法解决。我使用我的ipad作为设备使用xcode测试应用程序,它不在苹果商店。如果我使用浏览器密钥,我不知道我需要使用哪个链接,如果我尝试使用ios密钥,它就不起作用。我试图插入在phonegap安装过程中生成的bundle idenfier(com.example.pas-si)和我在我的ipad中用来测试应用程序的Apple证书中签名的那个(它。 quidfarm.approva)。
我已经从开发者控制台激活了正确的api,因为应用程序只在我的设备上,所以我无法解决配额问题。
我认为有一些基本设置,我没有以正确的方式设置。
我已使用Phonegap完成了我的应用,并使用本指南安装了地理定位http://www.devx.com/wireless/implement-google-maps-api-on-phonegap-using-the-device-api.html
这是我的map.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>Pas.si</title>
</head>
<body>
<div data-role="page" id="page" style="background-color:transparent;" >
<!-- ....Menu and other Html stuffs -->
<div id="content">
<div id="geolocation" style="width: 600px; height: 300px;">
</div>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/mappa.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=MY-API-KEY&sensor=false">
</script>
<script type="text/javascript">
app.initialize();
</script>
</div> <!-- END #content -->
<!-- .... other Html stuffs -->
</div> <!-- END #page -->
<!-- Java to shows a menu - not for geolocalization -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$('#menu').click(function() {
$('#listamenu').toggleClass('classmenub classmenua');
});
</script>
</body>
</html>
这是我的map.js
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
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 explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
// Get our current location
navigator.geolocation.getCurrentPosition(app.onSuccess, app.onError);
},
// Current location was found
// Show the map
onSuccess: function(position) {
var longitude = position.coords.longitude;
var latitude = position.coords.latitude;
var latLong = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
center: latLong,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("geolocation"), mapOptions);
},
// Current location could not be determined
// Show error
onError: function(error) {
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
},
};
我正在使用phonegap 3.3,Xcode 5.0.2。在OS 10.8.5的Mac Book Pro上
谢谢你,抱歉我的英文不好,希望你能理解这个问题。
答案 0 :(得分:1)
由于GoogleMaps API v3不需要API密钥,因此您暂时可以将其删除。
将来,如果达到使用限制,可能需要重新添加。在这种情况下,您需要进一步了解如何将应用程序命名空间添加到API密钥实例。