English 中文(简体)
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" 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>

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.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签