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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:36:23+00:00 2026-05-13T08:36:23+00:00

The code in question is the code contained within the 2nd foreach loop, the

  • 0

The code in question is the code contained within the 2nd foreach loop, the purpose of which is to prevent exact duplicate latitude and longitudes.

foreach($aUsers as $k => $v)
{
    // generate address
    $aAddress = array();
    if(!empty($v['city_location']))
        $aAddress[] = $v['city_location'];
    if(!empty($v['country_child_id']))
    {
        $aRow = $oDb->select('name')
             ->from(getT('country_child'))
             ->where('child_id = \''.$v['country_child_id'].'\'')
             ->execute('getRow');
        $aAddress[] = $aRow['name'];
    }
    if(!empty($v['postal_code']))
        $aAddress[] = $v['postal_code'];
    if(!empty($v['country_iso']))
    {
        $aRow = $oDb->select('name')
             ->from(getT('country'))
             ->where('country_iso = \''.$v['country_iso'].'\'')
             ->execute('getRow');
        $aAddress[] = $aRow['name'];
    }
    $sAddress = implode(', ',$aAddress);
    /// get location
    $aLatLon = $oGeoMap->getLatLon($v['user_id'],1,$sAddress);
    if($aLatLon['success'] === true)
    {
        foreach($aUsers as $k2 => $v2)
        {
            $iAdd = .01;
            $iAttempts = 0;
            while($v2['latitude'] == $aLatLon['latitude'] && $v2['longitude'] == $aLatLon['longitude'])
            {
                $iAttempts++;
                switch($iAttempts){
                    case 1:
                        $aLatLon['latitude'] += $iAdd;
                        break;
                    case 2:
                        $aLatLon['longitude'] += $iAdd;
                        break;
                    case 3:
                        $aLatLon['latitude'] += $iAdd;
                        $aLatLon['longitude'] += $iAdd;
                        break;
                    case 4:
                        $aLatLon['latitude'] -= $iAdd;
                        $aLatLon['longitude'] -= $iAdd;
                        break;
                    case 5:
                        $aLatLon['latitude'] += $iAdd;
                        $aLatLon['longitude'] -= $iAdd;
                        break;
                    case 6:
                        $aLatLon['latitude'] -= $iAdd;
                        $aLatLon['longitude'] += $iAdd;
                        break;
                    case 7:
                        $iAdd += .01;
                        $iAttempts = 0;
                        break;
                }
            }
        }
        $aUsers[$k]['latitude'] = $aLatLon['latitude'];
        $aUsers[$k]['longitude'] = $aLatLon['longitude'];
        $aUsers[$k]['address'] = $sAddress;
    }
    else
        unset($aUsers[$k]);
}
  • 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-13T08:36:23+00:00Added an answer on May 13, 2026 at 8:36 am

    I strongly agree with Frank Farmer’s comment, but if you insist on this way of doing things try something along these lines:

    $lls = array();
    static $offs = array( array(1,0), array(0,1), array(1,1),
        array(-1,-1), array(1,-1), array(-1,1) );
    
    foreach($aUsers as $k=>&$v) {
        $lla=$la=somelat; $llo=$lo=somelong;
        for($add=.01;isset($lls["{$lla}x$llo"]);$add+=.01) {
            foreach($offs as $o) {
                $lla=$la+$o[0]*$add; $llo=$lo+$o[1]*$add;
                if(!isset($lls["{$lla}x$llo"])) break;
            }
        }
        $lls["{$lla}x$llo"] = true;
        $v['latitiude']=$lla; $v['longtitude']=$llo;
        $v['address'] = $sAddress;
    }
    

    That is, if I understand your intention correctly. And change variable names to adhere to your standards yourself 😉

    Code is untested.

    And no, I’m not going to re-read the full code 😉

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

Sidebar

Related Questions

I'm working on a code for a form contained within a table. I'm writing
I have a simple question, which should hopefully have a quick answer. The code
sorry if this is a newB question, please conider the following code: #include <boost/multi_index_container.hpp>
This isn't a code question for once, but it definitely has me confused. Basically,
This is more of a licencing issue than a code question. I really like
In answering this code golf question , I ran across a problem in my
This is a code review question more then anything. I have the following problem:
Here is the code in question: import wx class MyFrame(wx.Frame): This is MyFrame. It
Hi here is the code in question and the issues that i am getting,
I apologize for making my first question not the hard-hitting code-related question I was

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.