Please help on how to find out the longitude and latitude from a routerequest RRS feed

  • Question

  • could someone please explain how to I get the longitude and latitude from this routerequest.

    I need to know the lat/long of the from address the long/lat of the via1 address and the long/lat of the to address

    I am trying to add a pushpin for each location in the request.

    it is a windows store app that I am creating

     string from = FromTbx.Text;
     string to = ToTbx.Text;
     string via1 = ViaTbx.Text;
    //Create the Request URL for the routing service
     Uri routeRequest = new Uri(string.Format("{0}&vwp.1={1}&wp.2={2}&rpo=Points&key={3}&maxSolns=3",from, via1, to, map.Credentials));
    //Make a request and get the response
    Response r = await GetResponse(routeRequest);

    Saturday, August 3, 2013 11:59 AM


All replies

  • Use the actual start property of each route leg for the From and via1 locations. Use the actual end property for the to location.

    Monday, August 5, 2013 8:49 AM
  • I don't really know how to do that. it all seems so complicated. so I am trying to take the following approach,

    'Here is the REST request
    Uri routeRequest1 = new Uri(string.Format("{0}&maxResults=3&key={1}", address, map.Credentials));
    'Here I process the response
    Response vi1 = await GetResponse(routeRequest1);
    'Here I create the pushpin
    Pushpin v1 = new Pushpin()
        Text = "V1",
        Background = new SolidColorBrush(Colors.Red)
    'The problem starts here where I try to add the pushpin to the map
    MapLayer.SetPosition(v1, new Bing.Maps.Location(vi1.ResourceSets[0].Resources[0].Coordinates[1],     vi1.ResourceSets[0].Resources[0].Coordinates[1]));
    The error message I get is the following

    Error:Index was outside the bounds of the array: Locator

    Am I missing something ? please help

    Thank you

    Tuesday, August 6, 2013 8:58 PM
  • The issue in your code is that you ar using the longitude value from the service as both the latitude and longitude value in when setting the position. Take a look at the last line of code and the crrdinate array index you are using (1 for both lat and long values, should be 0 and 1).

    Wednesday, August 7, 2013 10:07 AM
  • Sorry about that this was a last second error. actually when I fix that I get this error

    Error: Object reference not set to an instance of an object: Locator

    maybe this could help. there are no coordinates, value null    hmmmm
    Wednesday, August 7, 2013 8:55 PM
  • Let's take a step backwards here.The coordinate property as it's not a part of the base resource class. There is a Point property that the Coordinate comes from like this:

    var l = r.ResourceSets[0].Resources as BingMapsRESTService.Common.JSON.Location;
    var location = new Bing.Maps.Location(l.Point.Coordinates[0], l.Point.Coordinates[1]);

    I've written a couple of blog posts on how geocode in Windows store apps. Take a look at these posts:

    Thursday, August 8, 2013 9:02 AM
  • Thank allot it is clearer now, actually I found out two ways of doing that so the first way is with a REST request and the second one is with a geocode request. which one is better to be used ?

    here is the code for placing a pushpin at a location given an address using the REST request,

     private async void GetDirections3(string via)
                Uri geocodeUri = new Uri(string.Format("{0}&key={1}",
                   via, map.Credentials));
                    //Get response from Bing Maps REST  services 
                    Response r = await GetResponse(geocodeUri);
                    if (r != null &&
                        r.ResourceSets != null &&
                        r.ResourceSets.Length > 0 &&
                        r.ResourceSets[0].Resources != null &&
                        r.ResourceSets[0].Resources.Length > 0)
                        LocationCollection locations = new LocationCollection();
                        int i = 1;
                        foreach (TheLocator.Classes.Location l in r.ResourceSets[0].Resources)
                            //Get the location of each result 
                            Bing.Maps.Location location = new Bing.Maps.Location(l.Point.Coordinates[0], l.Point.Coordinates[1]);
                            //Create a pushpin each location 
                            Pushpin pin = new Pushpin()
                                Tag = l.Name,
                                Text = i.ToString()
                            //Set the location of the pushpin 
                            MapLayer.SetPosition(pin, location);
                            //Add the pushpin to the map 
                        await new MessageDialog("No results found.").ShowAsync();

    here is the code for placing a pushpin at a location given an address using the geocode request,

    public async void PerformSearch(string via1)
                // Set the address string to geocode
                Bing.Maps.Search.GeocodeRequestOptions requestOptions = new Bing.Maps.Search.GeocodeRequestOptions(via1);
                // Make the geocode request 
                Bing.Maps.Search.SearchManager searchManager = map.SearchManager;
                Bing.Maps.Search.LocationDataResponse response = await searchManager.GeocodeAsync(requestOptions);
                //ShowMessage("The best address match is: " + response.LocationData[0].Address.AddressLine);
                Pushpin vi1 = new Pushpin()
                    Text = "via",
                    Background = new SolidColorBrush(Colors.Green)
                    new Bing.Maps.Location(response.LocationData[0].Location.Latitude,

    Thursday, August 8, 2013 3:14 PM
  • Unless you need the route information for something other than finding the coordinates of your locations use the Geocoding service. The geocoding service is much faster and downloads a lot less data to your app.

    Friday, August 9, 2013 9:05 AM