0

次の関数は機能しますが、コードの改善を検討しています。最初にやりたいことは、「myOption」オブジェクト内のスタイルを削除して、前にそれらをロードし、AJAX 呼び出しからデータを取得する必要があるため、コンテンツのみを残すことです。

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

      var marker = new google.maps.Marker({
          position: marker.position,
          map: map,
          title: results[0].formatted_address
      });
      $.ajax({
        url: url+marker.position.ob+","+marker.position.pb+"",
        dataType: "jsonp",
        success: function (data) {
          var myOptions = {
               content: template(data)
              ,disableAutoPan: true
              ,maxWidth: 0
              ,pixelOffset: new google.maps.Size(-240, 0)
              ,zIndex: null
              ,boxStyle: { 
                background: "url('tipbox.gif') no-repeat"
                ,opacity: 0.9
                ,width: "454px"
               }
              ,closeBoxMargin: "10px 10px 2px -20px"
              ,closeBoxURL: "assets/image/x.png"
              ,infoBoxClearance: new google.maps.Size(1, 1)
              ,isHidden: false
              ,pane: "floatPane"
              ,enableEventPropagation: false
          };
          var ib = new InfoBox(myOptions);
          ib.open(map, marker);
        }
      });

    } 
    else {
      alert('Geocode was not successful for the following reason: ' + status);
    }

  });
}

スタイルオブジェクトを作成してAJAX呼び出しの前にロードし、それをデータを含むオブジェクトと結合して、「new InfoBox(NewObject)」内に単一のオブジェクトを渡すことを考えていました

これを行う方法についてのアイデアはありますか、それとも別の/より良い方法がありますか?

完全なスクリプト

4

1 に答える 1