3

jquery-ui-map を使用します。

いくつかのマーカーとマップの新しい中心の緯度/経度 (位置検索アプリケーション) を使用して、JSON を介してデータを読み込んでいます。

var origin = new google.maps.LatLng(data.origin.latitude, data.origin.longitude)

// adding the marker for the new origin works
$('#map_canvas').gmap('addMarker', {'position': origin});

// does not work
$('#map_canvas').gmap('center', '49, 7');

// does not work
$('#map_canvas').gmap('center', origin);

// does not work
$('#map_canvas').gmap('center', {'position': origin});

3 つのセンター コールはすべて失敗します。

Uncaught TypeError: Cannot call method 'apply' of undefined
$.a.$.fn.(anonymous function)jquery.ui.map.js:46
b.extend.eachjquery.js:35
b.fn.b.eachjquery.js:28
$.a.$.fn.(anonymous function)jquery.ui.map.js:40
(anonymous function)@@geosearch:477
c.extend.handleSuccessjquery.js:144
c.extend.ajax.w.onreadystatechange

ここでの標準的な方法は何ですか?

4

4 に答える 4

6

これを使って:

$('#map_canvas').gmap('get','map').setOptions({'center':origin});

次のリンクも参照してください: http ://code.google.com/apis/maps/documentation/javascript/reference.html#MapOptions

于 2012-03-05T08:41:48.690 に答える
4

マップを取得する方法とネイティブ セッターを使用する方法の 2 つがあります。

var map = $("#map_canvas").gmap("get", "map");
map.setCenter(origin);

または、プラグイン オプション セッターを使用します

$("#map_canvas").gmap("option", "center", origin);
于 2012-03-05T18:13:01.377 に答える