[英]Using Google Maps Directions API in android - what kind of API key is needed?
I'm embedding a map into my Android App and want to make it draw a route between two points. 我正在将地图嵌入到我的Android应用中,并希望使其绘制两点之间的路线。 However, I have no clue, how to get a correct key for Directions Api - the server returns "error_message" : "The provided API key is invalid."
但是,我不知道如何为Directions Api获取正确的密钥-服务器返回“ error_message”:“提供的API密钥无效。” as I'm trying to get the route via http request and using my android api key (a simple map and geolocation are working well with it).
因为我正在尝试通过http请求并使用我的android api键来获取路线(一个简单的地图和地理位置很好地配合了它)。 The request is (got from google docs examples):
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJ685WIFYViEgRHlHvBbiD5nE&destination=place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y&key=MyActualAndroidKey
该请求是(从Google文档示例中获取的):
https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJ685WIFYViEgRHlHvBbiD5nE&destination=place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y&key=MyActualAndroidKey
: https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJ685WIFYViEgRHlHvBbiD5nE&destination=place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y&key=MyActualAndroidKey
place_id: https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJ685WIFYViEgRHlHvBbiD5nE&destination=place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y&key=MyActualAndroidKey
place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJ685WIFYViEgRHlHvBbiD5nE&destination=place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y&key=MyActualAndroidKey
So, the question is: 因此, 问题是:
As API v. 3 do not prohibit using requests without key, the things work well without defining the key parameter in the query. 由于API v。3禁止使用没有密钥的请求,因此在不定义查询中的key参数的情况下,一切运行良好。 But it works not for all requests, and the request above won't work.
但是,它不适用于所有请求,并且上面的请求将不起作用。 Apparently, query like http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los%20Angeles,CA&sensor=false " works everywhere, including a browser. The difference between queries is in using place_id - it's possible to use it only with key.
显然,像http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los%20Angeles,CA&sensor=false之类的查询在任何地方都可以使用,包括浏览器。查询之间的区别在于使用place_id-只能与key一起使用。
I have integrated google direction api in one of my project and I have use server key for that. 我已经在我的项目之一中集成了Google Direction API,并且为此使用了服务器密钥。
go to https://console.developers.google.com enable google direction API create a server key user same key in the android to call direction API 转到https://console.developers.google.com启用谷歌Direction API在android中创建服务器密钥用户相同密钥以调用Direction API
yes. 是。 Obviously the key type should be server or none because you are using the web url (like https://maps.googleapis.com/maps/api/directions/json ?) instead of mobile sdk.
显然,密钥类型应该是服务器或不使用服务器,因为您使用的是Web网址(例如https://maps.googleapis.com/maps/api/directions/json ?),而不是移动SDK。
Mobile(Key restriction type is either Android or iOS ) API key will be required only when we use on mobile sdk to fetch and manipulate the google map feature. 仅当我们在移动SDK上使用以获取和操作Google Map功能时,才需要移动(密钥限制类型为Android或iOS )API密钥。
Note: Key restriction type None will be supported for all platform but recommended is specific type of restriction based on platform. 注:主要限制类型无将支持所有的平台,但建议是基于平台限制的具体类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.