ios - Google api key 不适用于我的 ios 应用程序

标签 ios google-maps cordova geolocation google-api


我在使用 phonegap 开发的 ios 应用程序中插入了地理定位。
当我打开我的 map.html 页面时,设备应该会在谷歌地图上显示我的位置。现在,当我打开 map.html 时,我收到了使用我的 gps 的请求,然后收到一条错误消息:“Google 禁用了此应用程序的 Google Maps API。提供的 key 不是有效的 Google API key ,或者它是未授权此站点上的 Google Maps API Javascript v3。如果您是此应用程序的所有者,您可以在此处找到更多信息:https://developers.google.com/maps/documentation/javascript/tutorial#api_key "

原来是api key的问题,我看了文档,网上也搜了,还是解决不了。我正在使用我的 ipad 作为设备使用 xcode 测试该应用程序,它不在苹果商店中。如果我使用浏览器 key 我不知道我需要使用哪个链接,如果我尝试使用 ios key 它不起作用。我试图插入在 phonegap 安装过程中生成的包标识符 (com.example.pas-si) 和我用来在我的 ipad 上测试应用程序的在我的苹果证书中签名的包标识符 (it.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 上

谢谢你,抱歉我的英语不好,希望你能理解这个问题。

最佳答案

由于 GoogleMaps API v3 不需要 API key ,您现在可以将其删除。

将来,如果您达到使用限制,您可能需要重新添加它。在这种情况下,您需要进一步了解如何将您的应用程序命名空间添加到 API key 实例。

关于ios - Google api key 不适用于我的 ios 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22412191/

相关文章:

java - AsyncRestTemplate '#' 查询参数中的符号编码

cordova - 无法将位置更改为本地文件,例如 Phonegap 3.5 中的 cdvfile ://path/index. html

visual-studio - Visual Studio 认为一切都是 TypeScript 资源

iPhone:将用户数据保存在 plist、SQLite 或 cookie 中?

ios - 我很困惑类扩展中声明的任何方法是否是静态的

postgresql - Postgis 经度、纬度转几何 postgresql

api - 明确 API 的含义

cordova - 如何发布WP8 Cordova应用程序?

ios - 如何以编程方式设置多值偏好?

ios - 如何防止以模态方式出现事件 Controller ?