Link to home
Start Free TrialLog in
Avatar of Marc Davis
Marc DavisFlag for United States of America

asked on

Bing Maps V8 and get multiple locations of pins to zoom out and show all pins?

Hi,

I am using Bing Maps V8. I have most activity in JavaScript with ASP.NET 4.0. The code behind, if applicable, is VB.NET.

But what is escaping me is there are several pins on a map and putting the pin is not a problem however getting the list of locations is.

I know Bing Maps V8 has the search but I'm searching for locations that are already pinned.

I need to zoom out to show the map with the area of all the pins.

How do I go about getting a list of all the pin locations to use to get the boundaries so I can zoom out the map?
Avatar of HainKurt
HainKurt
Flag of Canada image

so you are the one that adds pins...
when you add them in a loop I guess, you can easily find min/max coordinates
then call map api to set the boundaries...
Avatar of Marc Davis

ASKER

No individual users will add the necessary "pickup" in this situation.  Based on their address it will get the lat and long. The lat and long coordinates are stored in the DB.

So, as an administrator, I want to be able to read the DB which will post all the pins on the map. I want to use the map to list all the pins from the existing locations pinned and be able to get the bound to zoom the mapview to the proper zoom scope to see all the pins.

Boundaries can be set in the javascript functions based on the locations. I need to see about getting the list of pinned locations.
so from your database you can get max / min values + all your pins
then you put pins on map...
so, still, why you are trying to get data from client instead of database
I had an idea you were going to say that.

The thought had crossed my mind but I'd rather consume the client side memory rather than the DBMS. It's there on the client side memory. That is quicker and would no consume a lot.
I checked the api and found this

https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk#addMultipleLayerItems+JS

//var pins = Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds());
var pins = getPinsFromYourDB();;

var maxX = 0;
var maxY = 0;
var minX = 0;
var minY = 0;

for (i=0; i++;i<pins.length) {
  maxX = Math.max(maxX, pushpins[i].geometry.x);
  maxY = Math.max(maxY, pushpins[i].geometry.y);
  minX = Math.min(minX, pushpins[i].geometry.x);
  minY = Math.min(minY, pushpins[i].geometry.y);
}

// now do with maxX and MaxY
var viewRect = Microsoft.Maps.LocationRect.fromCorners(new Microsoft.Maps.Location(minX,minY), new Microsoft.Maps.Location(maxX,maxY));
map.setView({bounds: viewRect});

Open in new window

Yeah, I was looking at that as well with the example of 10 random pins.  But something came up in the middle.

However, I came to find out that the DB contains the items BUT the way this client is using the Bing Maps. All pins on stored on the map already so it's persistent on the map instance that the routing admins created. So it's on the map.entities already.

I need to get it in the locations and get the LocationRect from that then get the bounds from that to center the map. I think I might need to use the new Search functionality of the Spatial aspects.

I apologize I thought it was all from the database and I was incorrect on that. It's cost prohibitive - it's not cheap like from the enterprise and routing prospective.
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I haven't had a chance yet as priorities shifted but all the information looks great!

I will comment when it's implemented as well.
Yeah, that's actually not going to work. I don't have layers that are being used for the pins.