在我的网站中嵌入谷歌地图近似值(Embed a Google Map with approximation in my site)

编程入门 行业动态 更新时间:2024-10-26 22:19:36
在我的网站中嵌入谷歌地图近似值(Embed a Google Map with approximation in my site)

这就是我想要完成的事情(在我引入的地址周围找到一个带圆圈的地图而不标记确切的地址)

我有以下代码:

<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script> <div style='overflow:hidden;width:50%;'> <div id='gmap_canvas' style='height:440px;width:700px;'></div><div></div> <style>#gmap_canvas img{max-width:none!important;background:none!important}</style></div> <script type='text/javascript'> function init_map(){var myOptions = {zoom:10,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(51.5073509,-0.12775829999998223)});google.maps.event.addListener(marker, 'click', function(){infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomListener(window, 'load', init_map);</script>

这产生了这个结果:

我的问题是:

如何在给定地址周围制作圆圈? 我知道这是生成标记的代码,我想删除它并制作圆圈

marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(51.5073509,-0.12775829999998223)})

非常感谢

UPDATE

新规范

<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'> </script><div style='overflow:hidden;width:50%;'> <div id='gmap_canvas' style='height:440px;width:700px;'></div> <style>#gmap_canvas img{max-width:none!important;background:none!important}</style></div><script type='text/javascript'>function init_map(){var myOptions = {zoom:13,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);myCircle = new google.maps.Circle({strokeColor:'#FF0000',strokeOpacity:0.8,strokeWeight:2,fillColor:'#FF0000',fillOpacity:0.35,map:map,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),radius:100;});google.maps.event.addDomListener(window, 'load', init_map);</script>

我删除了:

marker = new google.maps.Marker({map:map,position:new google.maps.LatLng(51.5073509,-0.12775829999998223)})

包括:

myCircle = new google.maps.Circle({strokeColor:'#FF0000',strokeOpacity:0.8,strokeWeight:2,fillColor:'#FF0000',fillOpacity:0.35,map:map,center:new google.maps.LatLng(51.5073509) ,-0.12775829999998223),半径:100;})

This is what I'm trying to accomplish (getting a map with a circle around the address I introduce without marking the exact address)

I have the following code:

<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script> <div style='overflow:hidden;width:50%;'> <div id='gmap_canvas' style='height:440px;width:700px;'></div><div></div> <style>#gmap_canvas img{max-width:none!important;background:none!important}</style></div> <script type='text/javascript'> function init_map(){var myOptions = {zoom:10,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(51.5073509,-0.12775829999998223)});google.maps.event.addListener(marker, 'click', function(){infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomListener(window, 'load', init_map);</script>

That produces this result:

My question is:

How do I make the circle around the giving address? I know this is the code that produces the marker and I would like to remove that and make the circle around

marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(51.5073509,-0.12775829999998223)})

Thank you so much

UPDATE

New Code

<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'> </script><div style='overflow:hidden;width:50%;'> <div id='gmap_canvas' style='height:440px;width:700px;'></div> <style>#gmap_canvas img{max-width:none!important;background:none!important}</style></div><script type='text/javascript'>function init_map(){var myOptions = {zoom:13,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);myCircle = new google.maps.Circle({strokeColor:'#FF0000',strokeOpacity:0.8,strokeWeight:2,fillColor:'#FF0000',fillOpacity:0.35,map:map,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),radius:100;});google.maps.event.addDomListener(window, 'load', init_map);</script>

I removed:

marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(51.5073509,-0.12775829999998223)})

and included:

myCircle = new google.maps.Circle({strokeColor:'#FF0000',strokeOpacity:0.8,strokeWeight:2,fillColor:'#FF0000',fillOpacity:0.35,map:map,center:new google.maps.LatLng(51.5073509,-0.12775829999998223),radius:100;})

最满意答案

您可以使用圆而不是标记

var myCircle = new google.maps.Circle({ strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35, map: map, center: new google.maps.LatLng(51.5073509,-0.12775829999998223), radius: 100 });

You can use circle instead of marker

var myCircle = new google.maps.Circle({ strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35, map: map, center: new google.maps.LatLng(51.5073509,-0.12775829999998223), radius: 100 });

更多推荐

本文发布于:2023-08-05 19:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1438325.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:近似值   地图   网站   Embed   site

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!