提案されたアプリケーションに Bing Maps を使用することについて調査していて、壁にぶつかりました。一般的な考え方は、場所から X 距離以内にあるさまざまなアイテムの場所を表示したいということです。開始点は米国の地図で、ユーザーのクリックを使用して緯度/経度を取得し、それを使用して最も近い都市を選択します。そこにマップを中央に配置し、指定された距離内に各アイテムの画鋲をロードします。
デモを作成する方法として、次のように記述しました。私が直面している問題は、plotZipcode の landMap.Find への呼び出しがサイレントに失敗することです。エラー メッセージは表示されず、landMap.Find の前後にコンソール出力が期待どおりに表示されますが、plotPushpin は実行されません。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-us"></script>
<script type="text/javascript">
var landMap = null;
function getLatLong(evt) {
var latLong = landMap.PixelToLatLong(new VEPixel(evt.mapX, evt.mapY));
// This looks up the nearest city from the lat/long
// and returns something like "EAGLE CREEK, IN"
$.ajax({
url: '/cfc/bing.cfc',
data: {
method: 'findCity',
Latitude: latLong.Latitude,
Longitude: latLong.Longitude
},
success: plotZipcode
});
}
function plotPushpin(layer, results, places, expectMore, errorMessage) {
console.log('Executing plotPushpin...');
if (landMap && places && places.length >= 1) {
var pushpin = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
pushpin.SetTitle('Available Repos Near '+places[0].Name);
landMap.AddShape(pushpin);
}
}
function plotZipcode(data, textStatus, XMLHttpRequest) {
console.log('Executing plotZipcode...');
if (landMap && data.length > 0) {
console.log(data);
landMap.Clear();
console.log('Calling VEMap.Find...');
landMap.Find(null, data, null, null, null, null, null, null, null, null, plotPushpin);
//landMap.Find(null, data); // This doesn't work either.'
console.log('Called VEMap.Find!');
}
}
$(document).ready(function() {
landMap = new VEMap('landLocation');
landMap.LoadMap();
landMap.ShowDisambiguationDialog(false);
landMap.AttachEvent('onclick', getLatLong);
});
</script>
<div id='landLocation' style="position:absolute; width:600px; height:400px;"></div>
特に苛立たしいのは、Firebug を使用して以下を手動で実行すると、期待どおりに動作することです。
landMap.Find(null, "EAGLE CREEK, IN", null, null, null, null, null, null, null, null, plotPushpin);
VEMap.Find が単に AJAX コールバック内から何もしない理由についての洞察をいただければ幸いです。