2

I'm working on Android application with Google maps v2. And in my case I have several points that have same LA/LO, and this creates some UX problems one is select the point on map... So I need to get this points with same LA/LO and add some meters for each one, for example 50m to have a good distance and it can avoid the problems. How can I do this calc to incremente meters on LA/LO ?

Thanks so much!

user2578504
  • 59
  • 1
  • 5
  • as much i understood you want to add some meters to given lat, lng. Right? – Sandeep Nov 06 '13 at 04:09
  • http://stackoverflow.com/questions/7477003/calculating-new-longtitude-latitude-from-old-n-meters – Sandeep Nov 06 '13 at 04:22
  • Take a look at "declusterification" demo here: https://play.google.com/store/apps/details?id=pl.mg6.android.maps.extensions.demo source code is linked – MaciejGórski Nov 06 '13 at 08:18
  • http://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location – MilapTank Mar 11 '15 at 13:38

1 Answers1

4

Here is a method that takes Coordinates, a distance in meters and a bearing in degrees and returns the new coordinate.

public static Coordinate calcEndPoint(Coordinate center , int distance, double  bearing)
  {
      Coordinate gp=null;

      double R = 6371000; // meters , earth Radius approx
      double PI = 3.1415926535;
      double RADIANS = PI/180;
      double DEGREES = 180/PI;

      double lat2;
      double lon2;

      double lat1 = center.getDoubleLat() * RADIANS;
      double lon1 = center.getDoubleLon() * RADIANS;
      double radbear = bearing * RADIANS;

     // System.out.println("lat1="+lat1 + ",lon1="+lon1);

      lat2 = Math.asin( Math.sin(lat1)*Math.cos(distance / R) +
              Math.cos(lat1)*Math.sin(distance/R)*Math.cos(radbear) );
      lon2 = lon1 + Math.atan2(Math.sin(radbear)*Math.sin(distance / R)*Math.cos(lat1),
                     Math.cos(distance/R)-Math.sin(lat1)*Math.sin(lat2));

     // System.out.println("lat2="+lat2*DEGREES + ",lon2="+lon2*DEGREES);

      gp = new Coordinate( lon2*DEGREES, lat2*DEGREES);

      return(gp);
  }
harryr
  • 106
  • 5