<< It's All Relative | Home | android:layout_alignBaseline vs android:layout_alignBottom >> | JADe Central | Contact Us

Latitude, Longitude to GeoPoint

Android Snippets

So how do you get a GeoPoint(int , int) from a double latitude, longitude>?

As GeoPoint coordinates are based in micro-degrees i.e.(degrees * 1E6) you can simply do the maths every time:

GeoPoint gp = new GeoPoint((int)(latitude* 1E6), (int)(longitude* 1E6)); 

...or extend GeoPoint():

private static final class GeoPointD extends GeoPoint {     
  public GeoPointD(double latitude, double longitude) {         
    super((int) (latitude * 1E6), (int) (longitude * 1E6));     
  } 
}

Then it is simply a case of:

GeoPoint point = new GeoPointD(37.234569, -122.123456);

...or wrapped in a neat little 'util' class:

package com.gojade.map.util;

import com.google.android.maps.GeoPoint;

public class MapUtil
{
  public static GeoPoint getGeoPoint(double latitude, double longitude) {
    return new GeoPointD(latitude, longitude);    
  }

  private static final class GeoPointD extends GeoPoint {
    public GeoPointD(double latitude, double longitude) {
        super((int) (latitude * 1E6), (int) (longitude * 1E6));
    }
  }
  
}

Mappy Happing!

Export this post as PDF document  Export this post to PDF document




Add a comment Send a TrackBack