当前位置: 首页 > news >正文

github中Keyless Google Maps API在网页中显示地图和标记 无需api key

使用Google Maps API在网页中显示地图和标记的示例博客。以下是一个简单的示例:
C:\pythoncode\blog\google-map-markers-gh-pages\google-map-markers-gh-pages\index.html
在这里插入图片描述

介绍:

在本篇博客中,我们将学习如何使用Google Maps API在网页中显示地图,并在地图上添加标记。Google Maps API提供了丰富的功能和灵活性,使我们可以在网页中集成地图和地理信息。

步骤:

  • 创建一个新的HTML文件,并将以下代码保存为index.html
 <!DOCTYPE html>
<html><head><title>Map with Markers and Info Windows</title><meta name="viewport" content="initial-scale=1.0"><meta charset="utf-8"><style>/* Always set the map height explicitly to define the size of the div* element that contains the map. */#map {height: 100%;}/* Optional: Makes the sample page fill the window. */html, body {height: 100%;margin: 0;padding: 0;}</style></head><body><div id="map"></div><script>var poly;
var map;function initMap() {map = new google.maps.Map(document.getElementById('map'), {zoom: 7,center: {lat: 41.879, lng: -87.624}  // Center the map on Chicago, USA.});poly = new google.maps.Polyline({strokeColor: '#000000',strokeOpacity: 1.0,strokeWeight: 3});poly.setMap(map);// Add a listener for the click eventmap.addListener('click', addLatLng);
}// Handles click events on a map, and adds a new point to the Polyline.
function addLatLng(event) {var path = poly.getPath();// Because path is an MVCArray, we can simply append a new coordinate// and it will automatically appear.path.push(event.latLng);// Add a new marker at the new plotted point on the polyline.var marker = new google.maps.Marker({position: event.latLng,title: '#' + path.getLength(),map: map});
}</script><script src="https://cdn.jsdelivr.net/gh/somanchiu/Keyless-Google-Maps-API@v5.9/mapsJavaScriptAPI.js"></script></body>
</html>

请在页面源代码中加入 <script src="https://cdn.jsdelivr.net/gh/somanchiu/Keyless-Google-Maps-API@v5.9/mapsJavaScriptAPI.js">。确保你无需输入Maps JavaScript API,也可使用Google地图服务。

  • 在浏览器中打开index.html文件,你会看到一个地图显示在页面上,并且有一个标记在地图上显示出来。

总结:

在本篇博客中,我们学习了如何使用Google Maps API在网页中显示地图,并添加标记。通过使用Google Maps API和一些简单的JavaScript代码,我们可以轻松地集成地图和地理信息到我们的网页中。

参考

https://github.com/somanchiu/Keyless-Google-Maps-API/tree/master
http://www.noobyard.com/article/p-txwklxur-bm.html

http://www.lryc.cn/news/132449.html

相关文章:

  • ComPDFKit PDF SDK for Windows Crack
  • React+Typescript 状态管理
  • stable diffusion 运行时报错: returned non-zero exit status 1.
  • el-popover弹窗修改三角样式或者位置
  • Linux驱动开发之点亮三盏小灯
  • 【SA8295P 源码分析】71 - QAM8295P 原理图参考设计 之 MIPI DSI 接口硬件原理分析
  • macOS(m1/m2)破解Sublime Text和Navicat16
  • 【排排站:探索数据结构中的队列奇象】
  • Mac OS 中JDK 环境(jdk 1.8.0_831)安装配置、环境变量配置及卸载操作
  • [JAVAee]Tomcat - Servlet
  • MAC钓鱼并Root权限上线CS并权限维持,以及所有的坑如何解决
  • 浅谈OCR中的David Shepard
  • draw.io导出矢量图到word报错text is not svg - cannot display
  • JVM加强
  • 解决Oracle中XML插入数据时的空格问题
  • 微服务中间件--分布式事务
  • 计算机网络(9) --- 数据链路层与MAC帧
  • 【学会动态规划】环绕字符串中唯一的子字符串(25)
  • CNN卷积详解(三)
  • 使用 Amazon Redshift Serverless 和 Toucan 构建数据故事应用程序
  • CentOS 上快速安装包管理工具Conda
  • opencv-手势识别
  • 【SA8295P 源码分析】10 - HQX Display(OpenWFD)qcdisplaycfg_ADP_STAR_LA.xml 配置文件解析
  • 达梦数据库权限和预定角色介绍
  • Python编程从入门到实践_8-8 用户的专辑_答案
  • HummingBird 基于 Go 开源超轻量级 IoT 物联网平台
  • 10.小程序样式
  • Flink 流式读写文件、文件夹
  • 【SA8295P 源码分析】64 - QNX 与 Android GVM 显示 Dump 图片方法汇总
  • 字符串旋转(1)