Google Map API方向指示(iOS应用) [英] Google Map API Key in Directions (iOS app)

查看:88
本文介绍了Google Map API方向指示(iOS应用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用google map api在两个位置之间进行路由.在我的IOS应用程序中.我尝试为项目创建公共密钥,并在开发人员控制台中启用使用API​​.但我收到此错误:此IP站点或移动应用程序无权使用此api密钥IOS.出现此错误后,我尝试为(IP地址(Web服务器,cron作业等))的密钥限制创建API密钥,并设置我的ip地址,然后路由工作正常.但是,当我一次又一次地从其他设备尝试此操作时,出现此错误. 我应该使用该URL进行路由:

i want to use google map api for route between two location. in my IOS application. i try create public key for project and enable uses API in developer console. but i got this error: this ip site or mobile application is not authorized to use this api key IOS. after this error i try create API key for Key restriction for (IP addresses (web servers, cron jobs, etc.)) and set my ip address and then routing is work fine. but when i try this from other device again and again i get this error. i should use this URL for routing :

let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving&key=APIKEY"

如何在所有设备上使用我的代码来解决此问题.

how can solve this problem for working my code in all devices.

推荐答案

您与Google Maps Web服务一起使用的API密钥(Directions API)支持IP限制,如以下文档所述:

The API key that you use with Google Maps web service (Directions API) supports an IP restriction as mentioned in the following document:

https://developers.google.com/maps/faq #using-google-maps-apis

问题是您无法知道安装了应用程序的所有设备的IP地址.

The issue is that you cannot know the IP addresses of all devices where your application is installed.

您有以下选择:

  1. 使用不受限制的API密钥.请注意,API密钥需要HTTPS连接,因此不会对请求本身进行拦截,因为该请求是经过加密的.因此,在这种情况下,您应确保API密钥不直接放在源代码中.如果您可以从config或环境中读取它,那可能是可行的.

  1. Use unrestricted API key. Note that API key requires HTTPS connection, so the API key won't be intercepted from the request itself, because the request is encrypted. So, in this case you should procure that the API key is not put directly in your source code. If you can read it from config or the environment, it might be feasible.

创建一个中间服务器.您的iOS应用程序应将请求发送到中间服务器,中间服务器应将请求发送到Google并将响应传递回您的应用程序.在这种情况下,您可以通过中间服务器的IP地址来限制API密钥.

Create an intermediate server. Your iOS application should send requests to the intermediate server, intermediate server should send requests to Google and pass responses back to your app. In this case you can restrict an API key by IP address of your intermediate server.

我希望这会有所帮助!

这篇关于Google Map API方向指示(iOS应用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆