将标记添加到现有的Google地图(不刷新Google地图) [英] Add marker to existing google map (without refresh google map)

查看:121
本文介绍了将标记添加到现有的Google地图(不刷新Google地图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上(生产中)有一个带有少量标记的google地图,我想知道是否可以在不刷新我的google地图的情况下在现有地图上添加标记.

I have a google map on my website (in production) with few markers, i would like to know if its possible to add a marker on an existing map without refresh my google map.

这是我拥有的:

  • 我加载了我的网页,出现了带有标记的google地图

  • I load my webpage, google map appears with markers

在单击按钮时,我想在我的地图上添加一个标记(不刷新我的页面或google地图)

On click on a button, i would like to add one marker on my map (without refresh my page or the google map)

我可以通过刷新Google地图来实现这一点,但是由于每天Google地图显示的限制,我认为最好不刷新就可以做到这一点.

I can realize this with refresh my google map but i think that its better to do this without refresh due to limitation of google map display per day.

这是我的代码:

    <button onclick="addMarker()">Add marker</button>
<script>
    function addMarker(){
    var myLatLng = new google.maps.LatLng(44, 6);
    var marker = new google.maps.Marker({
                position: myLatLng,
                map: map,
            });
    }
</script>

推荐答案

var latlng = new google.maps.LatLng(42.745334, 12.738430);

function addmarker(latilongi) {
    var marker = new google.maps.Marker({
        position: latilongi,
        title: 'new marker',
        draggable: true,
        map: map
    });
    map.setCenter(marker.getPosition())
}

$('#btnaddmarker').on('click', function() {
    addmarker(latlng)
})

这篇关于将标记添加到现有的Google地图(不刷新Google地图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆