谷歌地图在一个国家的标记

Google maps marker in one country

本文关键字:国家 一个 谷歌地图      更新时间:2023-09-26

有人知道如何使用javascript api在谷歌地图中启用特定国家的标记吗?

这是我的代码与初始化映射的选项:(在其他方法中,我显示它,它工作):

latitud = "-33.400491820565236";
    longitud = "-70.68363189697266";
    //Se crea un objeto MapOptions con los valores de la lat y long para centrarlas
    var mapOptions = {
        center: new google.maps.LatLng(latitud, longitud),
        zoom: 7,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    //Se crea un objeto de tipo Map para que el mapa se muestre en el div especificado
    mapPunto2 = new google.maps.Map(document.getElementById(idDivMapa), mapOptions);

我只想为智利启用标记。谢谢。

您是否尝试过检查GeoCoder功能?https://developers.google.com/maps/documentation/javascript/geocoding

只需知道国家名称,就可以返回LAT和LONG并添加标记

例子:

geocoder = new google.maps.Geocoder();
function setCountryToSelect(countryToSelect) {
geocoder.geocode( { 'address': countryToSelect}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
       map.setCenter(results[0].geometry.location);
       var marker = new google.maps.Marker({
           map: map,
           position: results[0].geometry.location
       });
    } else {
      alert("Error: " + status);
    }
});
}
setCountryToSelect('USA');
setCountryToSelect('England');