【问题标题】:Google Directions API not authorizing access iOSGoogle Directions API 未授权访问 iOS
【发布时间】:2015-03-26 10:37:57
【问题描述】:

我正在尝试使用 Google Directions API,但没有成功。我在开发者控制台以及 Directions API 上激活了适用于 iOS 的 Google Maps SDK。

这是我使用的网址:

https://maps.googleapis.com/maps/api/directions/json?origin=48.581380,7.767050&destination=48.581100,7.766790&key=API_KEY

我收到了This IP, site , or mobile application is not authorized to use this API Key

我使用的密钥是 iOS API 密钥。

我在其他几个关于这个问题的问题中看到它可能与 iOS API 密钥和浏览器 API 密钥有关。我没有尝试过浏览器 API Key,因为这个问题和我的几乎一样:no result for query directions API iOS

谁能指出我正确的道路或告诉我我错过了什么?

【问题讨论】:

    标签: ios google-maps ios7 ios8 google-directions-api


    【解决方案1】:

    您的网址未正确附加API KEY

    https://maps.googleapis.com/maps/api/directions/json?origin=48.581380,7.767050&destination=48.581100,7.766790&key=API_KEY

    回复

    {
       "error_message" : "The provided API key is invalid.",
       "routes" : [],
       "status" : "REQUEST_DENIED"
    }
    

    API_KEY 无效,如果您将其留空或输入正确的密钥,您将得到结果: https://maps.googleapis.com/maps/api/directions/json?origin=48.581380,7.767050&destination=48.581100,7.766790&key=

    回复

    {
       "routes" : [
          {
             "bounds" : {
                "northeast" : {
                   "lat" : 48.5813851,
                   "lng" : 7.7670545
                },
                "southwest" : {
                   "lat" : 48.5810993,
                   "lng" : 7.7667977
                }
             },
             "copyrights" : "Datos de mapas ©2015 Google",
             "legs" : [
                {
                   "distance" : {
                      "text" : "39 m",
                      "value" : 39
                   },
                   "duration" : {
                      "text" : "1 min",
                      "value" : 6
                   },
                   "end_address" : "Strasbourg University, 6 Rue Blaise Pascal, 67000 Strasbourg, Francia",
                   "end_location" : {
                      "lat" : 48.5810993,
                      "lng" : 7.7667977
                   },
    
    // continues json answer....
    

    对不起,如果这是您的应用程序中的变量,或者是错字...

    【讨论】:

    • 我实际上并没有将“API_KEY”放在我的链接上。我把它放在这个问题上是因为我不想放弃它。我没试过不放钥匙,这是个好主意。我现在试试,告诉你这是否有效。
    • 没有钥匙也可以工作(不足为奇),但我不明白为什么我的钥匙不被接受...您对此还有其他想法吗?我会投票赞成你的答案,如果其他人没有其他建议,我会接受。
    • 您的密钥无效,但我不明白为什么。检查它,这是您在应用中看不到地图的唯一原因。
    【解决方案2】:

    我也在努力解决同样的问题。在完成所有基本步骤之后,这对我有帮助。

    1. 在创建 API 密钥时,将应用程序限制设置为“无”,将 API 限制设置为“限制密钥”,并添加 Directions API、Places API 和 Maps SDK for iOS。不要忘记“保存”更改。
    2. 将您的 API 密钥添加到 AppDelegate.swift 文件中
    3. 在代码中,将此 API 密钥添加到 URL 字符串中
    4. 保存文件,清理构建并运行应用程序

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2012-11-19
      • 2013-04-06
      • 1970-01-01
      • 2018-05-16
      • 2016-12-24
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多