amitesh
amitesh

Reputation: 860

How to create function for polyline in bing map?

I want to create a function in which i want to show poly line for A to B: I have two textbox A and B and submit button when i click on submit button my map show Polyline from A to B over sea.

Suppose if I enter newyork in first textbox and entered london in another one then it will show a polyline between two place over the sea in bing map.

Upvotes: 1

Views: 790

Answers (1)

Nicolas Tonneau
Nicolas Tonneau

Reputation: 606

The first think you have to do is to geocode the value of your textbox to get the locations of your to point. You can to that like this

var searchRequest = 'http://dev.virtualearth.net/REST/v1/Locations/' + query + '?output=json&jsonp=SearchServiceCallback&key=' + credentials;

Where the query is your textbox value, the credentials are your Bing Map key and the SearchServiceCallback is the callback of your function.

After that, with the two locations you can draw it on the map like that:

var polyline = new Microsoft.Maps.Polyline([new Microsoft.Maps.Location(51.533523,-0.118332), new Microsoft.Maps.Location(40.744136,-74.001389)]); 

map.entities.push(polyline); 

And your polyline will be draw.

Hope it help.

Upvotes: 2

Related Questions