簡體   English   中英

如何使用具有多個位置(地址和郵政編碼)的api v3繪制Google地圖?

[英]How can I draw google map using api v3 with multiple locations (address as well as zip codes)?

我處於需要使用具有多個位置的api v3繪制Google地圖的情況。 這些位置可以是“印度新德里”或110005之類的靜態地址字符串,但是它們的數目可能是多個-可以用逗號分隔或以數組的形式-我不知道確切地將它們如何放入代碼中。 但是我只是想繪制具有多個位置的gmap,所以給定的地圖將一次具有9或10個位置。 怎么做? 您能給我關於jsfiddle的任何工作代碼嗎? 現在,下面給出了僅在一個位置(僅地址而不是郵政編碼)繪制gmap的代碼-

JavaScript-

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var marker;
function initialize() 
{
    geocoder = new google.maps.Geocoder();
    var myOptions = {
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function codeAddress()
{
    //var address = "Talwara Township, Punjab";
    var address = document.getElementById("txtaddress").value;
    geocoder.geocode({'address': address}, function(results, status){       
        if(status == google.maps.GeocoderStatus.OK)
        {
            map.setCenter(results[0].geometry.location);
            marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
            });

            var infowindow = new google.maps.InfoWindow({
            content: "New Delhi, India"
            });
            infowindow.open(map, marker);

            // Click the marker to Zoom to 9
            google.maps.event.addListener(marker, 'click', function() {
                map.setZoom(9);
                map.setCenter(marker.getPosition());
            });
        } 
    });
}
</script>

HTML-

<body onLoad="initialize();codeAddress();">
<form method="get" action="">
<input type="text" id="txtaddress" name="txtaddress" size="30" value="New Delhi, India" />
<input type="submit" name="btnsubmit" value="Generate Map" />
</form>
<br /><br />
<div id="map_canvas" style="width:500px; height:380px; border:1px solid #AFAFAF;"></div>
</body>

您要問的是Batch GeoCoding 將多個地址更改為地理位置的過程稱為“批處理地理編碼”。

Google Maps API is not directly supporting BatchGeocoding. 
By using Google Maps API , We do geocode a single address at a time. 

To acheive BatchGeoCoding, We need to iterate a list of Address.(Not too difficult I think)

最佳做法: GeoCode示例

BatchGeocode參考:

以下是在線批處理地址解析網站。 供參考。

參考1參考2

工作演示

工作演示只是概念的證明。 必須以多種方式完善它。 請查看參考以產生更好的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM