Reputation: 1
I have two arrays of gps locations: lats[] and longs[] I use these arrays to place pushpins to a map. I would like to Zoom onto the area of the pushpins after they were placed. Please help me with the code to do that. Thank You.
function LoadPushPins()
{
var icon = new VECustomIconSpecification();
for (var i = 0; i < lats.length; i++)
{
var pp = new VEShape(VEShapeType.Pushpin, new VELatLong(lats[i],longs[i]));
pp.SetDescription(theaddress[i]);
pp.SetTitle(descs[i]);
icon.Image = theicon[i];
pp.SetCustomIcon(icon);
map.AddShape(pp);
}
}
Upvotes: 0
Views: 1983
Reputation: 17954
I notice you are using the old v6.3 version of Bing Maps. I highly recommend upgrading to the more powerful v7 of Bing Maps. That's also what the code from the others is based on. If you plan to stay on v6.3 (not recommended) you can do what you want by calculating the best center and zoom level for your array of coordinates and then passing this into the SetCenterAndZoom method of the map. Here is an old blog post on how to calculate these values: http://rbrundritt.wordpress.com/2009/07/21/determining-best-map-view-for-an-array-of-locations/
Note that the documentation for v6.3 isn't even online anymore, take this as a hint on it's future. You can find a migration guide to v7 here: http://social.technet.microsoft.com/wiki/contents/articles/20958.migrating-bing-maps-v6-3-to-v7.aspx
Upvotes: 0
Reputation: 4385
Bing provide a way to achieve the best view(location and zoom) for group of push pins.
var arrPushPinsLocations = [];
//Create array of locations using the longitude and latitude of yours pushpins.
arrPushPinsLocations.push(new Microsoft.Maps.Location(longitude, latitude));
//Create location rectangle object from arrPishPunsLocations and set the best view.
map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(arrPushPinsLocations)});
One exceptions, the LocationRect must contain at least two location points in order to work. The workaround is to add another virtual location that exactly near you real location. for example: Real: (54.000000, 54.0000000) Virtual: (54.000001, 54.0000001)
Upvotes: 2
Reputation: 8346
You can use Bing Map's setView method.
You can substitute your own latitude & longitude values.
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Map Credentials"});
map.setView({center:new Microsoft.Maps.Location(<latitude>, <longitude>), zoom: 9} );
Upvotes: -1