为Google的地理编码Web服务设置HTTP引荐来源网址 [英] Setting HTTP referrers for Google's geocoding web service

查看:156
本文介绍了为Google的地理编码Web服务设置HTTP引荐来源网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JS应用程序,该应用程序正在读取包含城市和州的URL,并对这些值进行地理编码以获得纬度和经度.我目前正在使用Google地理编码网络服务.

I have a JS application that is reading a URL which contains a city and state and geocoding those values to obtain a latitude and longitude. I am currently using the Google geocoding web service.

这对我的API密钥没有任何限制,但是工作正常,但是由于这是客户端JS,因此我尝试设置具有网站限制的HTTP引荐来源网址.当我将网站添加为HTTP引荐来源网址

This works fine with no restrictions on my API key but since this is client side JS I am trying to set HTTP referrers with website restrictions. When I add my site as an HTTP referrer

(https://*.mysite.com/*) 

应用程序中断.

https://maps.googleapis.com/maps/api/geocode/json?address=city,+state

我得到的唯一错误是

TypeError: Cannot read property 'geometry' of undefined

因为我没有返回任何数据.

because I am not returning any data.

我是否需要执行其他操作才能将此客户端与http引荐来源一起使用?我没有用户输入,因此我尝试不使用Google Maps API,因为Google文档说:

Do I have to do something additional to use this client side with http referrers? I have no user input so I am trying not to use the Maps API since the google documentation says:

Maps JavaScript API提供了一个地理编码器类,用于根据用户输入动态进行地理编码和反向地理编码.相反,如果您希望对静态的已知地址进行地理编码,请参阅地理编码Web服务.

The Maps JavaScript API provides a geocoder class for geocoding and reverse geocoding dynamically from user input. If instead you wish to geocode static, known addresses, see the Geocoding web service.

推荐答案

地理编码Web服务旨在用于服务器端,而不是JavaScript.您对与Web服务一起使用的密钥使用IP地址限制.如果要使用HTTP引荐来源网址,则需要使用Google Maps JavaScript API v3.

The Geocoding Web Service is meant to be used server side, not from JavaScript. You have to use IP Address restrictions on keys used with the web services. If you want to use HTTP referrers, you need to use the Google Maps JavaScript API v3.

这篇关于为Google的地理编码Web服务设置HTTP引荐来源网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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