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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:26:05+00:00 2026-05-26T19:26:05+00:00

I’m working on an iPhone app that is using GPS coordinates for leaderboards. I

  • 0

I’m working on an iPhone app that is using GPS coordinates for leaderboards. I don’t need the coordinates to be exact — actually I don’t ever want the coordinates to be exact, to protect user privacy.

I am specifying kCLLocationAccuracyThreeKilometers for desiredAccuracy, but when the GPS is active it seems it can also pick up the exact location when the device has it.

QUESTION: Is there any easy algorithm I can use to make the GPS data more coarse? Say, make it granular to 3km.

If I just scale the numbers up and remove decimal points and scale them down again it will make it more coarse in some parts of the world than others.

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-05-26T19:26:06+00:00Added an answer on May 26, 2026 at 7:26 pm

    While Mark’s answer above was a useful, it still did not yield a formula with consistent results because it relied on a random number generator.

    My buddy provided the best answer for this:

    Round the lat,lon to the nearest significant figure depending on the granularity, but this would result in all the lat/lons near a certain location, wind up in the same location. This method would use the distance between two points in lat/lon to calculate the rounding of the lat lon. Use the same formula below and set the course to 0, then the distance is your distance granularity. Calculate the resulting new lat/lon subtract the two lat/lons to get the rounding amount for lat. Then set the heading to 90 and recalculate and subtract the new lat/lon from the old to get the rounding amount for lon.

    And here’s the C++ code:

    class LocationUtility
    {
      public: static Location getLocationNow()
      {
        Location location;
    
        if(context != null)
        {
          double latitude = 0;
          double longitude = 0;
          ::of_getCurrentLocation(&latitude, &longitude);
    
          location.setLatitude(latitude);
          location.setLongitude(longitude);
    
          location = makeLocationCoarse(location);
        }
    
        return location;
      }
    
      public: static Location makeLocationCoarse(const Location& location)
      {
          double granularityInMeters = 3 * 1000;
          return makeLocationCoarse(location, granularityInMeters);
      }
    
      public: static Location makeLocationCoarse(const Location& location,
                 double granularityInMeters)
      {
        Location courseLocation;
    
        if(location.getLatitude() == (double)0 && 
          location.getLongitude() == (double)0)
        {
          // Special marker, don't bother.
        }
        else
        {
          double granularityLat = 0;
          double granularityLon = 0;
          {
            // Calculate granularityLat
            {
              double angleUpInRadians = 0;
              Location newLocationUp = getLocationOffsetBy(location, 
                granularityInMeters, angleUpInRadians);
    
              granularityLat = location.getLatitude() - 
                newLocationUp.getLatitude();
    
              if(granularityLat < (double)0)
              {
                granularityLat = -granularityLat;
              }
            }
    
            // Calculate granularityLon
            {
              double angleRightInRadians = 1.57079633;
              Location newLocationRight = getLocationOffsetBy(location,
                granularityInMeters, angleRightInRadians);
    
              granularityLon = location.getLongitude() - 
                newLocationRight.getLongitude();
    
              if(granularityLon < (double)0)
              {
                granularityLon = -granularityLon;
              }
            }
          }
    
          double courseLatitude = location.getLatitude();
          double courseLongitude = location.getLongitude();
          {
            if(granularityLon == (double)0 || granularityLat == (double)0)
            {
              courseLatitude = 0;
              courseLongitude = 0;
            }
            else
            {
              courseLatitude = (int)(courseLatitude / granularityLat) * 
                granularityLat;
    
              courseLongitude = (int)(courseLongitude / granularityLon) * 
                granularityLon;
            }
          }
          courseLocation.setLatitude(courseLatitude);
          courseLocation.setLongitude(courseLongitude);
        }
    
        return courseLocation;
      }
    
      // http://www.movable-type.co.uk/scripts/latlong.html
      private: static Location getLocationOffsetBy(const Location& location,
        double offsetInMeters, double angleInRadians)
      {
        Location newLocation;
    
        double lat1 = location.getLatitude();
        double lon1 = location.getLongitude();
    
        lat1 = deg2rad(lat1);
        lon1 = deg2rad(lon1);
    
        double distanceKm = offsetInMeters / (double)1000;
        const double earthRadiusKm = 6371;
    
        double lat2 = asin( sin(lat1)*cos(distanceKm/earthRadiusKm) + 
          cos(lat1)*sin(distanceKm/earthRadiusKm)*cos(angleInRadians) );
    
        double lon2 = lon1 + 
          atan2(sin(angleInRadians)*sin(distanceKm/earthRadiusKm)*cos(lat1), 
          cos(distanceKm/earthRadiusKm)-sin(lat1)*sin(lat2));
    
        lat2 = rad2deg(lat2);
        lon2 = rad2deg(lon2);
    
        newLocation.setLatitude(lat2);
        newLocation.setLongitude(lon2);
    
        return newLocation;
      }
    
      private: static double rad2deg(double radians)
      {
        static double ratio = (double)(180.0 / 3.141592653589793238);
        return radians * ratio;
      }
    
      private: static double deg2rad(double radians)
      {
        static double ratio = (double)(180.0 / 3.141592653589793238);
        return radians / ratio;
      }
    
      /*
      public: static void testCoarse()
      {
        Location vancouver(49.2445, -123.099146);
        Location vancouver2 = makeLocationCoarse(vancouver);
    
        Location korea(37.423938, 126.692488);
        Location korea2 = makeLocationCoarse(korea);
    
        Location hiroshima(34.3937, 132.464);
        Location hiroshima2 = makeLocationCoarse(hiroshima);
    
        Location zagreb(45.791958, 15.935786);
        Location zagreb2 = makeLocationCoarse(zagreb);
    
        Location anchorage(61.367778, -149.900208);
        Location anchorage2 = makeLocationCoarse(anchorage);
      }*/
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.