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

  • Home
  • SEARCH
  • 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 6388955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:38+00:00 2026-05-25T03:20:38+00:00

I am dynamically plotting several points onto a google map. I’m trying to find

  • 0

I am dynamically plotting several points onto a google map. I’m trying to find the best way to find the center of the given points. I’ve tried using the following:

var mapArray = new Array;
mapArray[0] = new Array(42, 35.391228, -119.008401);
mapArray[1] = new Array(34, 33.874277, -118.131555);
mapArray[2] = new Array(214, 32.6922592, -115.4962203);
mapArray[3] = new Array(216, 33.3818875, -117.2449785);
mapArray[4] = new Array(40, 36.805231, -119.770192);
mapArray[5] = new Array(47, 37.638266, -122.117398);
mapArray[6] = new Array(218, 37.638266, -122.117398);
mapArray[7] = new Array(39, 33.70677, -116.241719);
mapArray[8] = new Array(219, 33.666489, -117.30137);
mapArray[9] = new Array(37, 34.0625743, -118.354077);
mapArray[10] = new Array(217, 34.0625743, -118.354077);
mapArray[11] = new Array(43, 34.195561, -119.179495);
mapArray[12] = new Array(220, 37.671111, -121.873443);
mapArray[13] = new Array(215, 33.736294, -116.405587);
mapArray[14] = new Array(35, 33.978778, -117.383186);
mapArray[15] = new Array(36, 32.8321559, -117.1264585);
mapArray[16] = new Array(46, 37.312298, -121.930904);
mapArray[17] = new Array(221, 1, 1);
mapArray[18] = new Array(41, 33.7453974, -117.8502537);
mapArray[19] = new Array(44, 34.426024, -119.697417);
mapArray[20] = new Array(45, 34.952801, -120.440045);
mapArray[21] = new Array(38, 34.199697, -118.571618);

var avgLat = 0;
var avgLng = 0;
var j = 0;

for (var i in mapArray) {

    avgLat = (avgLat + mapArray[i][1]);
    avgLng = (avgLng + mapArray[i][2]);

    j++;
}

avgLat = avgLat / j;
avgLng = avgLng / j;

map.setCenter(new GLatLng(avgLat, avgLng), 6);

But that doesn’t give me an accurate center. What’s the best way to dynamically plot the center of the map?

  • 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-25T03:20:39+00:00Added an answer on May 25, 2026 at 3:20 am

    Find the max and min for both lat and long and then center on (max-min)/2 for each.

    That should be (max + min) / 2, the average.

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

Sidebar

Related Questions

How would you dynamically subscribe to a C# event so that given a Object
I'm trying to dynamically generate a report in a table where the borders are
I dynamically add rows to divStaff using jquery: $(span[id$='lblAddStaff']).click(function() { //$(.staff_tpl).find(input[id$='txtRate']).val(0,00); var staff_row =
I am trying to dynamically have my javascript look for an element ID in
I dynamically create a button in the way I found in the Internet: Page
I'm trying to dynamically update cells in a UITableView . The events are triggered
I'm trying to dynamically accept a table name depending on the conditions satisfied, also
I'm trying to dynamically create this function: svg.path($('#shape23'), path.move(333,410) .smoothC(333,410,333,410) .smoothC(217.5,415.75,217.5,415.75) .smoothC(333,500,333,500) .close(), {fill:
I am trying to dynamically create a generic Dictionary based on the type of
I am trying to dynamically change the font and background color of my app

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.