private Route directions(final GeoPoint start, final GeoPoint dest) { Parser parser; //https://developers.google.com/maps/documentation/directions/#JSON <- get api String jsonURL = "http://maps.googleapis.com/maps/api/directions/json?"; final StringBuffer sBuf = new StringBuffer(jsonURL); sBuf.append("origin="); sBuf.append(start.getLatitudeE6()/1E6); sBuf.append(','); sBuf.append(start.getLongitudeE6()/1E6); sBuf.append("&destination="); sBuf.append(dest.getLatitudeE6()/1E6); sBuf.append(','); sBuf.append(dest.getLongitudeE6()/1E6); sBuf.append("&sensor=true&mode=driving"); parser = new GoogleParser(sBuf.toString()); Route r = parser.parse(); return r; }
public class OsmdroidDemoMap extends Activity { private MapView mMapView; private MapController mMapController; int mIncr = 10000; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.osm_main); mMapView = (MapView) findViewById(R.id.mapview); mMapView.setTileSource(TileSourceFactory.MAPNIK); mMapView.setBuiltInZoomControls(true); mMapView.setMultiTouchControls(true); mMapController = mMapView.getController(); mMapController.setZoom(13); GeoPoint gPt0 = new GeoPoint(51500000, -150000); GeoPoint gPt1 = new GeoPoint(gPt0.getLatitudeE6()+ mIncr, gPt0.getLongitudeE6()); GeoPoint gPt2 = new GeoPoint(gPt0.getLatitudeE6()+ mIncr, gPt0.getLongitudeE6() + mIncr); GeoPoint gPt3 = new GeoPoint(gPt0.getLatitudeE6(), gPt0.getLongitudeE6() + mIncr); mMapController.setCenter(gPt0); PathOverlay myPath = new PathOverlay(Color.RED, this); myPath.addPoint(gPt0); myPath.addPoint(gPt1); myPath.addPoint(gPt2); myPath.addPoint(gPt3); myPath.addPoint(gPt0); mMapView.getOverlays().add(myPath); } }
public void recieveLongClick(MotionEvent ev) { Projection p = mapView.getProjection(); GeoPoint geoPoint = p.fromPixels((int) ev.getX(), (int) ev.getY()); // You can now pull lat/lng from geoPoint }
Projection proj = mapView.getProjection(); GeoPoint topLeft = proj.fromPixels(0, 0); GeoPoint bottomRight = proj.fromPixels(mapView.getWidth()-1, mapView.getHeight()-1); double topLat = topLeft.getLatitudeE6()/1E6; double topLon = topLeft.getLongitudeE6()/1E6; double bottomLat = bottomRight.getLatitudeE6()/1E6; double bottomLon = bottomRight.getLongitudeE6()/1E6;
@Override public boolean onTouchEvent(MotionEvent pEvent, MapView pMapView) { return super.onTouchEvent(pEvent, pMapView); } }
new Thread(new Runnable() { public void run() { final double lon = p.getLongitudeE6() / 1E6; final double lat = p.getLatitudeE6() / 1E6; final double alt = getAltitude(lon, lat); msg.append("Lon: ");
Projection proj = mapView.getProjection(); GeoPoint topLeft = proj.fromPixels(0, 0); GeoPoint bottomRight = proj.fromPixels(mapView.getWidth()-1, mapView.getHeight()-1); double topLat = topLeft.getLatitudeE6()/1E6; double topLon = topLeft.getLongitudeE6()/1E6; double bottomLat = bottomRight.getLatitudeE6()/1E6; double bottomLon = bottomRight.getLongitudeE6()/1E6;
if (Action == MotionEvent.ACTION_UP){ if(!moveMap) { Projection proj = myMapView.getProjection(); GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY()); //remove the last marker myMapView.getOverlays().remove(0); centerLocation(loc); }
selectedLatitude = geoPoint.getLatitudeE6(); selectedLongitude = geoPoint.getLongitudeE6(); return super.onTap(geoPoint,mapView);
Projection proj = mapView.getProjection(); GeoPoint topLeft = proj.fromPixels(0, 0); GeoPoint bottomRight = proj.fromPixels(mapView.getWidth()-1, mapView.getHeight()-1); double topLat = topLeft.getLatitudeE6()/1E6; double topLon = topLeft.getLongitudeE6()/1E6; double bottomLat = bottomRight.getLatitudeE6()/1E6; double bottomLon = bottomRight.getLongitudeE6()/1E6;
public float getDistanceInMiles(GeoPoint p1, GeoPoint p2) { double lat1 = ((double)p1.getLatitudeE6()) / 1e6; double lng1 = ((double)p1.getLongitudeE6()) / 1e6; double lat2 = ((double)p2.getLatitudeE6()) / 1e6; double lng2 = ((double)p2.getLongitudeE6()) / 1e6; float [] dist = new float[1]; Location.distanceBetween(lat1, lng1, lat2, lng2, dist); return dist[0] * 0.000621371192f; }
public class YourMapActivity extends MapActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mv = new EnhancedMapView(this, "<your Maps API key here>"); mv.setClickable(true); mv.setBuiltInZoomControls(true); mv.setOnZoomChangeListener(new EnhancedMapView.OnZoomChangeListener() { @Override public void onZoomChange(MapView view, int newZoom, int oldZoom) { Log.d("test", "zoom changed from " + oldZoom + " to " + newZoom); } } mv.setOnPanChangeListener(new EnhancedMapView.OnPanChangeListener() { public void onPanChange(MapView view, GeoPoint newCenter, GeoPoint oldCenter) { Log.d("test", "center changed from " + oldCenter.getLatitudeE6() + "," + oldCenter.getLongitudeE6() + " to " + newCenter.getLatitudeE6() + "," + newCenter.getLongitudeE6()); } } }
int nPixles = 5; //number of pixels GeoPoint g0 = mapview.getProjection().fromPixels(0, mapview.getHeight()/2); GeoPoint g1 = mapview.getProjection().fromPixels(nPixles, mapview.getHeight()/2); float[] results = new float[1]; Location.distanceBetween(g0.getLatitudeE6()/1E6, g0.getLongitudeE6()/1E6, g1.getLatitudeE6(), g1.getLongitudeE6()/1E6, results); float distanceInMeters = results[0];
GeoPoint topLeft = this.getProjection().fromPixels(getLeft(), getTop()); GeoPoint bottomRight = this.getProjection().fromPixels(getRight(), getBottom()); int topLat = topLeft.getLatitudeE6(); int topLng = topLeft.getLongitudeE6(); int bottomLat = bottomRight.getLatitudeE6(); int bottomLng = bottomRight.getLongitudeE6();
MapController mapControl = map.getController(); GeoPoint mapCenter = map.getMapCenter(); int latCenter = mapCenter.getLatitudeE6(); int longCenter = mapCenter.getLongitudeE6(); int latSpan = map.getLatitudeSpan(); int longSpan = map.getLongitudeSpan(); int latMax = latCenter + (latSpan / 2); int latMin = latCenter - (latSpan / 2); int longMax = longCenter + (longSpan / 2); int longMin = longCenter - (longSpan / 2);
mapView.getGlobalVisibleRect(currentMapBoundsRect); GeoPoint point1 = projection.fromPixels(currentMapBoundsRect.centerX(), currentMapBoundsRect.centerY()); GeoPoint point2 = projection.fromPixels(currentMapBoundsRect.left, currentMapBoundsRect.top); float[] results2 = new float[3]; Location.distanceBetween(point1.getLatitudeE6()/1E6, point1.getLongitudeE6()/1E6, point2.getLatitudeE6()/1E6, point2.getLongitudeE6()/1E6, results2);