locked
Why is VEMap.Find failing silently? RRS feed

  • Question

  • 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 a demonstration, 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>

    Any insight into why VEMap.Find is simply doing nothing would be appreciated.
    Monday, February 22, 2010 5:26 PM

Answers

  • In your ajax call you can add a callback for errors:

    $.ajax({
        url: '/cfc/bing.cfc',
        data: {
            method: 'findCity',
            Latitude: latLong.Latitude,
            Longitude: latLong.Longitude
        },
        success: plotZipcode,
        error: function(e){
            alert(e.responseText);
        }
    });


    Windows Live Developer MVP - http://rbrundritt.spaces.live.com | http://inknowledge.co.uk
    Monday, October 11, 2010 2:06 PM
    Moderator

All replies

  • A less than helpful reply I'm sure, but I do something close to what you're doing. My methodology is a little different though. I have a wcf service (set as "script service") that's called from javascript.

    The service in the back ground takes care of supplying the neighboring items to whatever location(s) are provided by the javascript call, and then plots them. The script service returns a class that looks like this:


    public class LocationResult
    {
    String Icon get;set;
    LatLong Coord get;set;
    Place[] Places get;set;
    }

    public class Place
    {
    String Icon get;set;
    LatLong Coord get;set;
    }
    Monday, February 22, 2010 6:33 PM
  • The idea in our case is that the user is starting at a country wide view of the map. A simple click in the appropriate region and my code will determine where they clicked, find the nearby items, and center the map at where they clicked, zoomed in see the various push pins in the region.

    I'm sure there's more effective ways to center the map at a location when you've got a VELatLong object in hand, but it should seem that since I've got "CITY, STATE" coming back to me in a string that VEMap.Find(null, data); should be an effective method...
    Monday, February 22, 2010 6:54 PM
  • Hi Eric,

    I have run into a problem similar to yours. I am callign using VEMap.Find method but the callback function for this method doesn't really get executed. Did you ever find a solution to your problem? Please let me know in case you have any suggestions as to why the callback function fails. Below is my code.

    I get the address to geocode from a 'textInput' textbox and want to add a pushpin on map after geocoding the address.

    Any suggestions are welcome.

    Thanks,

    Lovepreet

    function AddGeoPushpin() {
           //var geoAddress = document.getElementById("textInput");
           var geoPinAddress = document.getElementById('<%=textInput.ClientID%>').value;
    
           alert(geoPinAddress);
                         map.Find(null, // what
                           geoPinAddress, // where
                           null,  // VEFindType (always VEFindType.Businesses)
                           null,  // VEShapeLayer (base by default)
                           null,  // start index for results (0 by default)
                           null,  // max number of results (default is 10)
                           true,  // show results? (default is true)
                           true,  // create pushpin for what results? (ignored since what is null)
                           null,  // use default disambiguation? (default is true)
                           true,  // set best map view? (default is true)
                           GeocodeCallbackfun); // call back function
    
         }
    
         function GeocodeCallbackfun(pinshapeLayer, pinfindResults, pinplaces, pinmoreResults, pinerrorMsg) 
         {
           alert("GeocodeCallbackfun Called");
           // if there are no results, display any error message and return
           if (pinplaces == null) 
           {
             alert((pinerrorMsg == null) ? "There were no results" : pinerrorMsg);
             return;
           }
    
           var bestPlace = pinplaces[0];
    
           // Add pushpin to the *best* place
           var location = bestPlace.LatLong;
           var geoLatitude = location.Latitude;
           var geoLongitude = location.Longitude;
           //var confString = confidenceStrings[bestPlace.MatchConfidence];
           //var precString = precisionStrings[bestPlace.Precision];
           //var resHtml = "Geocoded Results<br />Latitude: " + geoLat + ", Longitude: " + geoLong + "<br /> Confidence: " + confString + "<br /> Precision: " + precString;
    
           var geoPushpin = new VEShape(VEShapeType.Pushpin, location);
          
           map.AddShape(geoPushpin);
           
          
         }
    
    
    Tuesday, July 27, 2010 5:35 PM
  • In your ajax call you can add a callback for errors:

    $.ajax({
        url: '/cfc/bing.cfc',
        data: {
            method: 'findCity',
            Latitude: latLong.Latitude,
            Longitude: latLong.Longitude
        },
        success: plotZipcode,
        error: function(e){
            alert(e.responseText);
        }
    });


    Windows Live Developer MVP - http://rbrundritt.spaces.live.com | http://inknowledge.co.uk
    Monday, October 11, 2010 2:06 PM
    Moderator