Why would Bing Maps' VEMap.Find be failing silently?
I'm doing some research on using Bing Maps for a proposed application and I've run into a wall. The general idea is that I want to show the locations of various items we have within X distance to a location. The start point is the US map and we're using the user's click to get lat/long, and using that to pick the nearest city. We'll center the map there and then load in pushpins for each of our items within the prescribed distance.
In the way of building a demo, I've written the following. The problem I'm running into is that the call to landMap.Find in plotZipcode is failing silently. There's no error message and the console output both before and after the landMap.Find is displaying as expected, but plotPushpin is never executed.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script charset="UTF-8" ty开发者_开发百科pe="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>
The particularly frustrating thing is that if I use Firebug to manually execute the following, it behaves exactly as expected:
landMap.Find(null, "EAGLE CREEK, IN", null, null, null, null, null, null, null, null, plotPushpin);
Any insight into why VEMap.Find is simply doing nothing from within my AJAX callback would be greatly appreciated.
The issue is a Firefox one. For some reason the JQuery doc ready function doesn't like to run with a reference to the function to load the map. If you place the mapload method in the body onload event (html or pure javascript - not jquery) it will work.
精彩评论