bolden / google-maps-api
Bolden为Craft CMS 3提供的Google Maps服务器端Web服务免费插件
1.0.3
2019-07-09 11:48 UTC
Requires
- craftcms/cms: ^3.0.0
This package is auto-updated.
Last update: 2024-09-09 19:54:28 UTC
README
一个简单的Google Maps服务器端Web服务包装器,通过AJAX调用访问。
要求
此插件需要Craft CMS 3或更高版本以及一个有效/活跃的Google Maps API密钥。
概述
使用此包装器访问只有通过服务器端连接才能访问的Google Maps Web服务。目前,此插件支持以下端点:
- 地理编码
- 时区
- 地点
- 自动完成
- 输入
- 详细信息
- 海拔
- 距离
配置
在插件设置中输入一个有效/活跃的Google Maps API密钥,非常简单。
用法
使用HTTP GET请求访问端点
api/googleMaps/geocode/<latitude>,<longitude>
根据纬度和经度返回地点
更多信息请见 Google Geocoding APIapi/googleMaps/timezone/<latitude>,<longitude>,<timestamp>
根据纬度、经度和时间戳返回地点的时区
更多信息请见 Google Timezone APIapi/googleMaps/place/autocomplete/<input>
根据文本输入(可以是地址、地点名称等)返回地点自动完成建议
更多信息请见 Places Autocomplete APIapi/googleMaps/place/text/<input>/<fields>
根据文本输入(可以是地址、地点名称等)返回地点。您还可以定义要返回的字段逗号分隔列表。更多信息请见 Places Search APIapi/googleMaps/place/details/<placeId>
根据地点ID返回地点详细信息。更多信息请见 Places Details APIapi/googleMaps/elevation/<lat>,<lon>
根据地点的纬度和经度返回海拔信息
更多信息请见 Elevation APIapi/googleMaps/distance/<originLat>,<originLon>,<destinationLat>,<destinationLon>,<mode>
根据起点和终点的纬度和经度返回海拔信息。您还可以选择模式(在驾驶、骑自行车、步行、公共交通之间选择)
更多信息请见 Distance Matrix API
示例
请求
GET https://www.example.com/api/googleMaps/geocode/52.3679843,4.903561399999944
响应
[ { "address_components": [ { "long_name": "662", "short_name": "662", "types": [ "street_number" ] }, { "long_name": "Waterlooplein", "short_name": "Waterlooplein", "types": [ "route" ] }, { "long_name": "Amsterdam-Centrum", "short_name": "Amsterdam-Centrum", "types": [ "political", "sublocality", "sublocality_level_1" ] }, { "long_name": "Amsterdam", "short_name": "Amsterdam", "types": [ "locality", "political" ] }, { "long_name": "Amsterdam", "short_name": "Amsterdam", "types": [ "administrative_area_level_2", "political" ] }, { "long_name": "Noord-Holland", "short_name": "NH", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "Netherlands", "short_name": "NL", "types": [ "country", "political" ] }, { "long_name": "1011 PG", "short_name": "1011 PG", "types": [ "postal_code" ] } ], "formatted_address": "Waterlooplein 662, 1011 PG Amsterdam, Netherlands", "geometry": { "location": { "lat": 52.3680461000000008198185241781175136566162109375, "lng": 4.90357839999999978175537762581370770931243896484375 }, "location_type": "ROOFTOP", "viewport": { "northeast": { "lat": 52.369395080291496924473904073238372802734375, "lng": 4.9049273802915021036596954218111932277679443359375 }, "southwest": { "lat": 52.36669711970849760973578668199479579925537109375, "lng": 4.90222941970849834802947952994145452976226806640625 } } }, "place_id": "ChIJ5zzsu70JxkcRQR-0VFl8Bl0", "plus_code": { "compound_code": "9W93+6C Amsterdam, Netherlands", "global_code": "9F469W93+6C" }, "types": [ "street_address" ] } ]
致谢
由 Bolden 制作,免费使用。