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 7961425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:01:52+00:00 2026-06-04T05:01:52+00:00

I have a multidimensional array of latitudes and longitudes, and one other single marker

  • 0

I have a multidimensional array of latitudes and longitudes, and one other single marker “m”. I need to get the two most closest points to “m” from the array for creating two other markers. Any help would be highly appreciated.

this is the array of lats and lons

var locations= [
                   ['loc1', 54.1121824,-1.3983992],
                   ['loc2', 54.2121824,-1.4323992],
                   ['loc3', 54.4121824,-1.5993992],
                   ['loc4', 54.3871874,-1.6773992],
                   ['loc5', 54.1963824,-1.5983992]
                 ];  

I want to get the most two closest points to m=54.1143824,-1.4963992 for creating two markers from them

  • 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-06-04T05:01:53+00:00Added an answer on June 4, 2026 at 5:01 am

    One of the components is using the geometry library function computeDistanceBetween(from:LatLng, to:LatLng, radius?:number) where radius is optional (Earth’s radius).

    You must include geometry with the JS API using the libraries parameter:

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>

    Now you can loop through your data, saving the computed distance between each coordinate and the special marker m. The result will be in meters by default (changing the radius optionally will give different units)

    For each row in the coordinates data, make a rowLatLng = new google.maps.LatLng(row[1], row[2])

    google.maps.geometry.spherical.computeDistanceBetween(rowLatLng, m.getPosition())

    Then, the best way I can think of extracting the two closest points is using an object { locationname: "loc1", distance: 20 } to save which point is being compared to marker “m”, and what the computed distance is. Even better, could be to save the “row” index from the locations variable so you can pull the coordinate easily.

    An array of these objects can then be sorted by distance. I found a post here: Sorting an array of JavaScript objects with the following answer for sorting homes by their price:

    homes.sort(function(a,b) { return parseFloat(a.price) - parseFloat(b.price) } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional array, I am interested in getting all the elements (one
I have a multidimensional array. The code below outputs one entire column. <?php for
I have a multidimensional array, and I need to sort that array by a
I have this multidimensional array. I need to search it and return only the
I have a multidimensional array. I need a function that checks if a specified
I have a multidimensional array. I need to search it for a specific range
i have this multidimensional array in php and I need be able to access
I have a multidimensional array which I would like to sort by two factors:
hi i have multidimensional array in php i want to remove an index from
I have a multidimensional array which I am looping through using a foreach loop.

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.