javascript - 我需要帮助理解的Javascript google map api函数
问题描述
我主要做后端工作,对 JavaScript 知之甚少(强调一点)。我遇到了一些嵌入在网站 html 页面中的 javascript 代码。现在我不确定这里发生了什么。
我的理解是,它是某种 javascript google map api 函数(也许我错了)。我需要了解的是它在做什么。
<script type="text/javascript" src="http://maps.googleapis.com/maps/api
/js?key=*********************&libraries=places">
</script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
/* mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
alert(mesg);*/
document.getElementById('locc').value = address;
document.getElementById('latttt').value = latitude;
document.getElementById('lonnnn').value = longitude;
});
});
</script>
<input type="hidden" name="loc" id="locc" value="">
<input type="hidden" name="latitu" id="latttt" value="">
<input type="hidden" name="longitu" id="lonnnn" value="">
解决方案
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
然后它根据来自谷歌地图的数据设置三个输入框的值。
(另外,在旁注中,我会在脚本标签中隐藏个人 api 密钥以防万一)
推荐阅读
- python - 读取多个 JSON 文件并将数据转换为单个 CSV 文件
- ms-access - 用于多个查询的 MS Access 报告
- javascript - echarts:dataZoom 滑块不显示正确的数据预览
- java - 重新索引 Solr:java.lang.OutOfMemoryError:Java 堆空间 solr
- groovy - 如何在 Groovy 中获取函数的输出
- android - Firebase IOS UTM 安装跟踪
- angular - Angular 8 上传中的多部分/表单数据
- python - Python/Numba:使用 Numba 扩展 API 创建自定义类型时遇到问题
- docker - docker-compose 将teampeak数据目录挂载为卷的问题
- php - 如何在 html php mysql 表中显示更多结果?