Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3391540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:48:53+00:00 2026-05-18T03:48:53+00:00

I’m working on some map stuff and I’m stuck with something that seems to

  • 0

I’m working on some map stuff and I’m stuck with something that seems to be quite basic.

The gist of what I’m doing is adding 10 flags to a map, and I need to dynamically set the zoom level and center of the map based on the position of the pins (map needs to be zoomed in as far as possible while still showing all pins).

This works exactly as expected with MultiMap without any intervention (as expected), but the Virtual Earth map doesn’t play nice. If I don’t give it a center Lat/Lon, it defaults to showing all of the USA.

Can anyone point me in the right direction in order to get this working?

EDIT:

Ok, I was able to calculate the proper center by using the following in my MVC Controller

''# we're going to rock the AVERAGE LAT/LON here
Dim eventCount As Integer = 0
Dim totalLat As Double = 0
Dim totalLon As Double = 0
For Each mel In MapEventList
    totalLat += mel.lat
    totalLon += mel.lon
    eventCount += 1
Next
ViewData("centerLat") = totalLat / eventCount
ViewData("centerLon") = totalLon / eventCount

Now I’m just stuck trying to calculate the Best Zoom Level

EDIT 2:

So I’ve removed the calculations from my controller and added it to my Javascript. The weight of the script is quite light, but will have the calculations done by the client machine and not my server (valuable if/when the site starts getting piles of hits)

$(document).ready(function () {
    // Load the Bing Map and populate it
    var increment = 0; // used to increment event locations
    var sumLat = 0; // used to find the average LAT location
    var sumLon = 0; // used to find the average LON location

    // Load the initial map
    LoadMap();

    // loop through all events and place a point on the map
    // also add to the sumLat and sumLon variable
    $.each(json_object, function () {
        increment = ++increment;
        sumLat = sumLat + this.lat;
        sumLon = sumLon + this.lon;
        LoadPoint(this.lat, this.lon, this.title, this.desc, increment);
    });

    // find the averate Lat and Lon for map centering
    var centerLat = sumLat / increment;
    var centerLon = sumLon / increment;
    LatLon = new VELatLong(centerLat, centerLon);

    // Set the new map Center based on the average of all points.
    map.SetCenter(LatLon)
});

function LoadMap() {
    map = new VEMap('bingMap');
    mapOptions = new VEMapOptions

    // sets map options for asthetics
    mapOptions.DashboardColor = "black";
    mapOptions.EnableDashboardLabels = false;
    mapOptions.EnableBirdseye = false;
    mapOptions.EnableDashboardLabels = false;

    // Load the initial map
    // note: the LatLon is "null" at this point because we are going to 
    // center the map later based on the average of all points.
    map.LoadMap(null, zoomLevel, null, null, null, false, null, mapOptions);

};

function LoadPoint(lat, lon, title, desc, pinId) {
    var point = new VELatLong(lat, lon);
    var pin = new VEShape(VEShapeType.Pushpin, point);
    pin.SetTitle(title);
    pin.SetDescription(desc + "<br /><br />lat: " + lat + " lon: " + lon);
    pin.SetCustomIcon("<div class='pinStyle'><div class='pinText'>" + pinId + "</div></div>");
    map.AddShape(pin);
};

However I’m still stuck trying to calculate the Best Zoom Level

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:48:53+00:00Added an answer on May 18, 2026 at 3:48 am

    If you are using the javascript version, then you don’t need to calculate it, you can directly give the array of VELatLong objects to VEMap.SetMapView, and it will center + zoom so that all pins are visible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.