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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:08:51+00:00 2026-06-04T12:08:51+00:00

The following JavaScript function was taken from http://sg.openrice.com/js/en/sdmap.js (web page that includes this external

  • 0

The following JavaScript function was taken from http://sg.openrice.com/js/en/sdmap.js
(web page that includes this external JS file: http://sg.openrice.com/singapore/restaurant/advancesearch.htm?mapType=1):

function showAllMarkers(data, options) {
    var markerGroups = {};
    var getcs = function (lat, lng) {
        return '' + Math.round(lat * 32768) + Math.round(lng * 32768);
    }
    for (var i = 0; i < data.length; i++) {
        if (markerList[data[i].id]) continue;
        if (!(data[i].lat == 0 && data[i]['long'] == 0)) {
            var xy = getcs(data[i].lat, data[i]['long']);
            if (markerGroups[xy]) {
                markerGroups[xy].push(data[i]);
            } else {
                markerGroups[xy] = [data[i]];
            }
        }
    }
    for (var i in markerGroups) {
        updateGroupMarker(markerGroups[i], options);
    }
}

After the script runs, the function is used to cluster overlapped markers. I totally understand the javascript syntax, but I don’t understand what this line does:

return '' + Math.round(lat * 32768) + Math.round(lng * 32768);

Is there any special purpose for multiplying by 32768? Can anyone explain to me?

Thanks!

  • 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-04T12:08:52+00:00Added an answer on June 4, 2026 at 12:08 pm

    That line is just some way of generating a string index (“hash”) for the array markerGroups. What you should learn from it is that “getcs” is an undescriptive name, it makes source code reading harder and you should give functions clearer names that make the meaning clear.

    Anyway: The rounding cuts away some digits. Since the author probably does not want to cut away to many digits he has to multiply lat/long with a large enough value to reduce the effect. It looks like 32768 is a more or less random choice (it is 2^15, seems still random).

    Ok, now to the collisions: Two coordinates that are very close to each other… Say 0.000001,0.000001 and 0.000002,0.000002 will cause the same hash to be generated. The author then uses these hashes to group all markers that have the same hash.

    This is a very simplistic algorithm. It accepts that if you have two markers that are literally right next to each other (like a millimeter distance between them), but it is just at the border where the hash value would change, the algorithm will not group them.

    In more illustrative words: The algorithm lays a grid over your map, each cell of the grid having the size 1°/32768 * 1°/32768 (that is approximately up to 3,4*3,4 meters per square on the equator, 3,4m * 2,2m in Germany/at the border between USA/Canada if the coordinate system is WGS84. The size of the square will vary a lot depending on position on earth) and every marker within one grid cell gets the same hash value and is consequently grouped together.

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

Sidebar

Related Questions

The below code is taken from http://bonsaiden.github.com/JavaScript-Garden/ function Foo() { this.value = 42; }
I have the following javascript function: <script type=text/javascript> function quickCardRegister_OnCompleteSave() { publishContent('This is a
Consider the following html snippet <!DOCTYPE html> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.4.2.js ></script> <script
I have taken following code from my template file, <a onclick=previewPop('<?= $this->url(array('controller'=>'report', 'action'=>'generatepreview','report_date'=>str_replace(%2F, /,
Given the following javascript: function foo(selectControl) { ... } and the following html: <select
For the following JavaScript: function EscapedString(str) { var obj = document.createElement(span); obj.innerHTML = str;
I use the following javascript function, function get_check_value(formId,checkboxId,TxtboxId) { alert(formId); var c_value = ;
my problem with the following javascript function: function ValidateDates() { var valid = false;
I have the following javascript method: function 123_test_function(){ } The function is generated by
I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling

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.