Google 本地主机和生产服务器的地图 API,截至 2019 年 4 月
Google Maps API for both localhost & production server, as of April 2019
TLDR
当以 file://<path>/index.html
访问时,我的代码在我的笔记本电脑上运行良好,但当以 http://<path>/index.html
访问时,我的代码在带有 Apache 服务器 运行 的笔记本电脑上运行良好,也不在我的真实(生产) 服务器。我在控制台上没有看到任何错误,但地图只是一个灰色矩形。
我已经有几年没编写任何 Google 地图应用程序了。
似乎,从去年开始,现在有必要通过向其提供信用卡详细信息并在每次 API 调用时提供一个 API 密钥。
不幸的是,有很多的信息,much/most其中的信息已过时and/or自相矛盾。
任何人都可以指出有关如何配置此功能的规范指南,最好带有屏幕截图吗?
我想画一张地图,并添加一些标记,这将需要反向地理编码,这样我提供一个街道地址并将其转换为 lat/long 以便放置标记。
听起来很简单,但是成千上万的 "helpful" 站点中有哪个是正确的?
比如the current Google help page好像说的是
From the Navigation menu, select APIs & Services > Credentials.
On the Credentials page, click Create credentials > API key
但我什至看不到那个菜单选项:-(
[更新] 如果有帮助,开发人员控制台中的错误消息说:
Geocoding Service: You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account For more information on authentication and Google Maps JavaScript API services please see: https://developers.google.com/maps/documentation/javascript/get-api-key
[更新] 我正在尝试这样访问 API
<script src="maps.google.com/maps/api/…>
和
var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + comapnyLocation +'&key=XXXX';
$http.get(url)
[Update++] 在开发人员控制台中,我看到了一堆错误:
aliextension.com/wp-content/uploads/2017/08/JAR.png:1 GET https://aliextension.com/wp-content/uploads/2017/08/JAR.png net::ERR_CONNECTION_TIMED_OUT
我不知道 aliextension
是什么,它也没有出现在我的代码中(也许在一些缩小的 JS 中?)
好的,跟速卖通(Ali Baba)有关。我删除了它,超时消息消失了,但我仍然遇到问题。
如果我将 index.html
作为 file://
加载到 Chrome 中,那么它工作得很好。但是,如果我将它加载为 http://,我有一个 Xampp Apache 服务器 运行,地图框仍然是灰色的,尽管我没有看到任何错误消息。同样的事情发生在我的真实服务器上:-(
造成这种情况的原因很可能是 API key restriction。
为了允许这些主机名或 IP 地址,您必须:
a) 转到 credentials panel 和 select 相应的项目,然后单击 "Api key"。
b) 在那里你可以放宽限制,对于 HTTP referrers
(对于网站)
... 或 IP addresses
(以防这些是服务器端请求)。
此页面应该是您的起点:
https://developers.google.com/maps/documentation/javascript/tutorial
它可以帮助您使用 Google 地图 javascript API.
要将 google 地图嵌入到您的网站,请阅读上面 link 中的概览页面。
要向您的 google 地图添加标记,请阅读此页面:
https://developers.google.com/maps/documentation/javascript/adding-a-google-map
要进行反向地理编码,请阅读此页面:
https://developers.google.com/maps/documentation/javascript/geocoding
我只需要使用 google 地图。我想你也可以这样做。
TLDR
当以 file://<path>/index.html
访问时,我的代码在我的笔记本电脑上运行良好,但当以 http://<path>/index.html
访问时,我的代码在带有 Apache 服务器 运行 的笔记本电脑上运行良好,也不在我的真实(生产) 服务器。我在控制台上没有看到任何错误,但地图只是一个灰色矩形。
我已经有几年没编写任何 Google 地图应用程序了。
似乎,从去年开始,现在有必要通过向其提供信用卡详细信息并在每次 API 调用时提供一个 API 密钥。
不幸的是,有很多的信息,much/most其中的信息已过时and/or自相矛盾。
任何人都可以指出有关如何配置此功能的规范指南,最好带有屏幕截图吗?
我想画一张地图,并添加一些标记,这将需要反向地理编码,这样我提供一个街道地址并将其转换为 lat/long 以便放置标记。
听起来很简单,但是成千上万的 "helpful" 站点中有哪个是正确的?
比如the current Google help page好像说的是
From the Navigation menu, select APIs & Services > Credentials.
On the Credentials page, click Create credentials > API key
但我什至看不到那个菜单选项:-(
[更新] 如果有帮助,开发人员控制台中的错误消息说:
Geocoding Service: You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account For more information on authentication and Google Maps JavaScript API services please see: https://developers.google.com/maps/documentation/javascript/get-api-key
[更新] 我正在尝试这样访问 API
<script src="maps.google.com/maps/api/…>
和
var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + comapnyLocation +'&key=XXXX';
$http.get(url)
[Update++] 在开发人员控制台中,我看到了一堆错误:
aliextension.com/wp-content/uploads/2017/08/JAR.png:1 GET https://aliextension.com/wp-content/uploads/2017/08/JAR.png net::ERR_CONNECTION_TIMED_OUT
我不知道 aliextension
是什么,它也没有出现在我的代码中(也许在一些缩小的 JS 中?)
好的,跟速卖通(Ali Baba)有关。我删除了它,超时消息消失了,但我仍然遇到问题。
如果我将 index.html
作为 file://
加载到 Chrome 中,那么它工作得很好。但是,如果我将它加载为 http://,我有一个 Xampp Apache 服务器 运行,地图框仍然是灰色的,尽管我没有看到任何错误消息。同样的事情发生在我的真实服务器上:-(
造成这种情况的原因很可能是 API key restriction。
为了允许这些主机名或 IP 地址,您必须:
a) 转到 credentials panel 和 select 相应的项目,然后单击 "Api key"。
b) 在那里你可以放宽限制,对于 HTTP referrers
(对于网站)
... 或 IP addresses
(以防这些是服务器端请求)。
此页面应该是您的起点: https://developers.google.com/maps/documentation/javascript/tutorial 它可以帮助您使用 Google 地图 javascript API.
要将 google 地图嵌入到您的网站,请阅读上面 link 中的概览页面。
要向您的 google 地图添加标记,请阅读此页面: https://developers.google.com/maps/documentation/javascript/adding-a-google-map
要进行反向地理编码,请阅读此页面: https://developers.google.com/maps/documentation/javascript/geocoding
我只需要使用 google 地图。我想你也可以这样做。