Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bing Maps Ajax API - get location from address

Tags:

bing-maps

I'm using Microsoft.Maps API (AJAX control v. 7). I want to display pin for an address. When I use:

var loc = new Microsoft.Maps.Location(47.592, -122.332);
var pOptions = {icon: 'img/ICN_Bullet_Blue_25x38.gif', text: '1'};
var pin = new Microsoft.Maps.Pushpin(loc, pOptions);

It's working fine. How can I get latitude and longitude from address, so I will later use it for pin location ?

like image 474
Filip Witkowski Avatar asked Jul 25 '13 20:07

Filip Witkowski


People also ask

How do I get Bing location?

You can click Change to adjust your location. Click Allow to allow Bing to access your current location. You can also enter it manually. If you choose to allow Bing to access your current location, you'll see a prompt asking for your location (if you haven't previously allowed or blocked a location request from Bing).

Is Bing geocoding API free?

If you're looking to start small with Bing Maps API or just want to give it a spin, the Basic key is completely free of cost.

Does Bing Maps have an API?

The Bing Maps Routing API enables optimized travel times both for consumers and commercial applications with location intelligence features using historical data.


1 Answers

Bing Maps includes geocoding support (finding location by addresses).

You have two options for this:

  • Use the REST api directly. http://msdn.microsoft.com/en-us/library/ff701714.aspx

In that page you can find plenty of examples. You make a REST HTTP request and obtain a JSON that includes the geocoded coordinates.

  • Use the Microsoft.Maps.Search module. http://msdn.microsoft.com/en-us/library/hh868060.aspx

You just load the module and then do something like:

var search = new Microsoft.Maps.Search.SearchManager(map);

search.geocode({where:"some address...", count:10, callback:geocodeCallback});

and then, in your callback just handle the results:

function geocodeCallback(geocodeResult, userData)
{
    var location = geocodeResult.results[0].location;
}
like image 139
psousa Avatar answered Oct 01 '22 12:10

psousa