在网页内嵌入地图的需求时常会用到,以下三种是最常见的方法:
Google Maps Embed API (内嵌网页)Google Static Maps API (静态地图图片)Google Maps JavaScript API (动态地图)优缺点比较
方法 | 运作方式 | 优点 | 缺点
------------- | -------------
Google Maps Embed API | iframe 嵌入地图 | 製作简单且呈现动态呈现 | 嵌入 iframe 效能最差
Google Static Maps API | 静态地图图片 | 效能最佳 | 只是一张图片,无法缩放、互动
Google Maps JavaScript API | 参数串接地图 | 客製化程度最高 | 串接资料需要有一定的程式能力
补充
嵌入 iframe 效能最差,是因为网页虽然只发出一个请求取得 iframe 的资讯,但 iframe 这个地图网页里又会发出了许多请求,像是取得定位资讯、附近地点、背景底图......等,才有办法呈现如此多的资讯,同时也会造成网页负担。
Embedded Maps – Best for Beginners
At the end of the day if you just want to keep it simple using the Google Maps Embed API is your best option available. There is some downsides in terms of customisation and loading times but if you’re looking for a simple solution embedding your map is by far the easiest to do.JavaScript Maps – Best for Experts
If you have a great level of control over your website’s code and know how to use JavaScript to an intermediate level using the Google Maps JavaScript API is the best option available for you. With such a wide range of control and practical applications you can integrate a map that fulfils any purpose you need it for.Static Maps – Best overall
Google Maps Static API is the best option available overall. Out of the box using a static maps is relatively easy with fast loading times, decent customisation available and the best set up for SEO. Unless you’re looking for a very easy or highly complicated solution, using a static map is the way to go.
参考来源:
https://kiwisprout.nz/post/google-maps--embedded-static-or-js--whats-better