0

実際の一意の有効なアドレスのリストなどの JSON データが与えられた場合:

var data = [
    { "address": "48 rue des Grands Moulins, 75013, Paris"},
    { "address": "12_rue_des_Grands_Moulins,_75013,_Paris"},
    { "address": "65_rue_des_Grands_Moulins,_75013,_Paris"},
    { "...": "..."},
    ];

これらの数百の住所のそれぞれは、地球上で一意であるのに十分詳細です。

次のような htmlを指定します。

<div id="map" style="height:40%;"></div>

このデータを使用して Google マップを作成し、自動的に入力するにはどうすればよいですか? JSfiddle に感謝します。

編集:ここで私のフィドルの現在の進歩。明日、データを JSON に移行し、ループを追加して各オブジェクトを反復処理します。

注: 番地を使用すると、次のクエリを使用して JSON 形式で geoloc 情報を取得できます。

4

2 に答える 2

2

のようなもの (テストされていません);

var location, map, objectID;

objectID  = "dom-id";

// Your gMap
//
map       = new google.maps.Map( document.getElementById( objectID ), {} );

// Put the following lines in your loop
// 
geocoder.geocode({ "address" : the_address_to_map }, function( results, status )
{
    if ( status == google.maps.GeocoderStatus.OK )
    {
        var latitude         = results[ 0 ].geometry.location.lat()
        ,   longitude        = results[ 0 ].geometry.location.lng()
        ;

        location = new google.maps.LatLng( latitude, longitude );

        if( location ) 
        {
            var marker          = new google.maps.Marker(
            {
                position    : location,
                title       : "",
                // other settings
            });

            marker.setMap( map );
        }
    }
});

このサービスの呼び出しには制限があります。1 日 2500 リクエストと考えていましたが、API コンソールで調べることができます。

于 2013-02-25T10:18:20.713 に答える
0
geoCodeLookupLL: function(addressstring, markerTitle, markerListeners) { 

  this.geocoder = new GClientGeocoder(); 
  this.markerStreetAddr = addressstring; 
  var map = this.getMap(); // Existing Map Object

  this.geocoder.getLatLng(addressstring, 

      function(point,markerTitle) { 

      if (!point) { 

      }else{ 
        Ext.applyIf(markerTitle,G_DEFAULT_ICON);         

        var new_icon = new GIcon()  

        new_icon.image = "https://maps.gstatic.com/mapfiles/ms2/micons/green-dot.png"  
        new_icon.size = new GSize(16,16)  
        new_icon.iconAnchor = new GPoint(9,34)
        new_icon.infoWindowAnchor = new GPoint(9,2)
        new_icon.title = markerTitle

        var mark = new GMarker(point,new_icon); 

        map.addOverlay(mark); 

      }
    }) 

住所を既存の地図の新しいマーカーとして使用しているため、新しいアイコン オブジェクトです。いくつかの V2 api メソッドも見つかる場合があります。

于 2013-02-25T16:38:08.117 に答える