######説明
住所を入力するとマップの位置が入力住所に移動し、その住所にマーカーを置くように実装しています。
######できていないこと
マーカーのリフレッシュができていません。
1回目の住所入力:入力住所にマーカーが立つ
2回目の住所入力:1回目のマーカー&2回目の入力住所にマーカーが立つ
↓
1回目の住所入力:入力住所にマーカーが立つ
2回目の住所入力:2回目の入力住所にマーカーが立つ(1回目のマーカーは削除)
としたいです。
######今のコード
HTML
1<form method="get" action="#" id="address_search"> 2 <div class="input-group form-group"> 3 <input type="text" id="address" class="form-control" placeholder="住所"> 4 <span class="input-group-btn"> 5 <button class="btn" type="submit" value="住所へ移動"> 6 <i class="glyphicon glyphicon-search"></i> 7 </button> 8 </span> 9 </div> 10 </form>
javascript
1/////////////////////////////////////////////////////////////////////// 2// 住所検索がクリックされた時 3/////////////////////////////////////////////////////////////////////// 4$(function() { 5 $('#address_search').submit(function(event) { 6 geocoder = new google.maps.Geocoder(); 7 var address = document.getElementById("address").value; 8 if (geocoder) { 9 geocoder.geocode( { 10 'address': address, 11 'region': 'jp' 12 },function(results, status) { 13 console.log(results); 14 if (status == google.maps.GeocoderStatus.OK) { 15 Yucho.map.setCenter(results[0].geometry.location); 16 var bounds = new google.maps.LatLngBounds(); 17 if (results[0].geometry) { 18 var latlng = results[0].geometry.location; 19 bounds.extend(latlng); 20 var icon = new google.maps.MarkerImage('webroot/images/map/ico.png', 21 new google.maps.Size(55,72),/*アイコンサイズ設定*/ 22 new google.maps.Point(0,0)/*アイコン位置設定*/ 23 ); 24 25 var marker = new google.maps.Marker({ 26 position: latlng, 27 icon: icon, 28 map: Yucho.map 29 }); 30 Yucho.markerArr.push(addressmarker); 31 } 32 //map.fitBounds(bounds); 33 } 34 }); 35 } 36 addressmarker.setMap(null); 37 }); 38}); 39
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/19 03:35