com.google.android.maps.MapView Java Examples

The following examples show how to use com.google.android.maps.MapView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CurrentLocation.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.main); // bind the layout to the activity

		// create a map view
		RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
		mapView = (MapView) findViewById(R.id.mapview);

//		ZoomControls mZoom = (ZoomControls) mapView.getZoomControls();
//		linearLayout.addView(mZoom);
		mapController = mapView.getController();
		// Zoon 1 is world view
		mapController.setZoom(14);
		locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
				0, new GeoUpdateHandler());

		overlays = mapView.getOverlays();
		Drawable drawable = this.getResources()
				.getDrawable(R.drawable.push_pin);
		itemizedoverlay = new MyOverlays(drawable);
		
	}
 
Example #2
Source File: MainActivity.java    From Android-Example with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	  MapView mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(true);
	    MapController mc = mapView.getController();
	    double lat1 = Double.parseDouble("48.85827758964043"); // latitude
	    double lon1= Double.parseDouble("2.294543981552124"); // longitude
	    double lat2 = Double.parseDouble("8.85827758964043"); // latitude
	    double lon2 = Double.parseDouble("22.294543981552124"); // longitude
	    double lat3 = Double.parseDouble("83.85827758964043"); // latitude
	    double lon3 = Double.parseDouble("22.294543981552124"); // longitude
	    GeoPoint geoPoint = new GeoPoint((int)(lat1 * 1E6), (int)(lon1 * 1E6));
	    mc.animateTo(geoPoint);
	    mc.setZoom(15);
	    mapView.invalidate();
	    List<Overlay> mapOverlays = mapView.getOverlays();
	    Drawable drawable = this.getResources().getDrawable(R.drawable.maker);
	    AddItemizedOverlay itemizedOverlay =
	    new AddItemizedOverlay(drawable, this);
	     
	    OverlayItem overlayitem1 = new OverlayItem(geoPoint, "Hello", "Sample Overlay item");
	    OverlayItem overlayItem2=new OverlayItem(geoPoint, "two", "this is two");
	    
	    itemizedOverlay.addOverlay(overlayitem1);
	    itemizedOverlay.addOverlay(overlayItem2);
	    mapOverlays.add(itemizedOverlay);
	    mapOverlays.add(itemizedOverlay);
}
 
Example #3
Source File: ShowMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onCreate(Bundle bundle) {
	super.onCreate(bundle);
	setContentView(R.layout.main); // bind the layout to the activity

	// Configure the Map
	mapView = (MapView) findViewById(R.id.mapview);
	mapView.setBuiltInZoomControls(true);
	mapView.setSatellite(true);
	mapController = mapView.getController();
	mapController.setZoom(14); // Zoon 1 is world view
	locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
			0, new GeoUpdateHandler());

	myLocationOverlay = new MyLocationOverlay(this, mapView);
	mapView.getOverlays().add(myLocationOverlay);

	myLocationOverlay.runOnFirstFix(new Runnable() {
		public void run() {
			mapView.getController().animateTo(
					myLocationOverlay.getMyLocation());
		}
	});

	Drawable drawable = this.getResources().getDrawable(R.drawable.point);
	itemizedoverlay = new MyOverlays(this, drawable);
	createMarker();
}
 
Example #4
Source File: CustomResourceProxyImpl.java    From android_frameworks_mapsv1 with Apache License 2.0 4 votes vote down vote up
public CustomResourceProxyImpl(Resources resources, DisplayMetrics displayMetrics) {
    this.resources = resources != null ? resources : MapView.DEFAULT_CONTEXT != null ? MapView.DEFAULT_CONTEXT.getResources() : null;
    this.displayMetrics = displayMetrics != null ? displayMetrics : this.resources != null ? this.resources.getDisplayMetrics() : generateDisplayMetrics();
}
 
Example #5
Source File: GoogleTilesOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(final Canvas c, final MapView osmv, final boolean shadow) {
	if (DEBUGMODE) {
              Log.d(Constants.LOGTAG, "draw");
	}

	// Calculate the half-world size
	final Projection pj = osmv.getProjection();
	final int zoomLevel = osmv.getZoomLevel() - 1;
	final int tileSizePx = this.mTileProvider.getTileSource().getTileSizePixels();

	// Calculate the tiles needed for each side around the center one.
	final int latSpan = osmv.getLatitudeSpan();
	final int longSpan = osmv.getLongitudeSpan();
	final int topLatitude = osmv.getMapCenter().getLatitudeE6() + latSpan/2;
	final int leftLongitude = osmv.getMapCenter().getLongitudeE6() - longSpan/2;
	final int bottomLatitude = osmv.getMapCenter().getLatitudeE6() - latSpan/2;
	final int rightLongitude = osmv.getMapCenter().getLongitudeE6() + longSpan/2;
	final Point leftTopXY = Mercator.projectGeoPoint(topLatitude*1E-6, leftLongitude*1E-6, zoomLevel, new Point(0,0));
	final Point rightBottomXY = Mercator.projectGeoPoint(bottomLatitude*1E-6, rightLongitude*1E-6, zoomLevel, new Point(0,0));
	final int tileNeededAtLeft = leftTopXY.x;
	final int tileNeededAtRight = rightBottomXY.x;
	final int tileNeededAtTop = leftTopXY.y;
	final int tileNeededAtBottom = rightBottomXY.y;

	final int mapTileUpperBound = 1 << zoomLevel;
	// make sure the cache is big enough for all the tiles
	final int numNeeded = (tileNeededAtBottom - tileNeededAtTop + 1)
			* (tileNeededAtRight - tileNeededAtLeft + 1);
	mTileProvider.ensureCapacity(numNeeded);
	/* Draw all the MapTiles (from the upper left to the lower right). */
	for (int y = tileNeededAtTop; y <= tileNeededAtBottom; y++) {
		for (int x = tileNeededAtLeft; x <= tileNeededAtRight; x++) {
			// Construct a MapTile to request from the tile provider.
			final int tileY = MyMath.mod(y, mapTileUpperBound);
			final int tileX = MyMath.mod(x, mapTileUpperBound);
			final long mapTileIndex = MapTileIndex.getTileIndex(zoomLevel, tileX, tileY);
			final Drawable currentMapTile = mTileProvider.getMapTile(mapTileIndex);
			if (currentMapTile != null) {
				final GeoPoint gp = new GeoPoint(
						(int) (Mercator.tile2lat(y, zoomLevel) * 1E6),
						(int) (Mercator.tile2lon(x, zoomLevel) * 1E6));
				pj.toPixels(gp, mTilePos);
				mTileRect.set(mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y + tileSizePx);
				currentMapTile.setBounds(mTileRect);
				currentMapTile.draw(c);
			}

			if (DEBUGMODE) {
				c.drawText(MapTileIndex.toString(mapTileIndex), mTileRect.left + 1, mTileRect.top + mPaint.getTextSize(), mPaint);
				c.drawLine(mTileRect.left, mTileRect.top, mTileRect.right, mTileRect.top, mPaint);
				c.drawLine(mTileRect.left, mTileRect.top, mTileRect.left, mTileRect.bottom, mPaint);
			}
		}
	}

	// draw a cross at center in debug mode
	if (DEBUGMODE) {
		final GeoPoint center = osmv.getMapCenter();
		final Point centerPoint = pj.toPixels(center, null);
		c.drawLine(centerPoint.x, centerPoint.y - 9, centerPoint.x, centerPoint.y + 9, mPaint);
		c.drawLine(centerPoint.x - 9, centerPoint.y, centerPoint.x + 9, centerPoint.y, mPaint);
	}
}
 
Example #6
Source File: GooglePolylineOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {

	if (shadow) {
		return;
	}

	final int size = mPoints.size();
	if (size < 2) {
		// nothing to paint
		return;
	}

	final Projection pj = mapView.getProjection();

	Point screenPoint0 = null; // points on screen
	Point screenPoint1;
	GeoPoint projectedPoint0; // points from the points list
	GeoPoint projectedPoint1;

	mPath.rewind();
	projectedPoint0 = mPoints.get(size - 1);

	for (int i = size - 2; i >= 0; i--) {
		// compute next points
		projectedPoint1 = mPoints.get(i);

		// the starting point may be not calculated, because previous segment was out of clip
		// bounds
		if (screenPoint0 == null) {
			screenPoint0 = pj.toPixels(projectedPoint0, mTempPoint1);
			mPath.moveTo(screenPoint0.x, screenPoint0.y);
		}

		screenPoint1 = pj.toPixels(projectedPoint1, mTempPoint2);

		// skip this point, too close to previous point
		if (Math.abs(screenPoint1.x - screenPoint0.x) + Math.abs(screenPoint1.y - screenPoint0.y) <= 1) {
			continue;
		}

		mPath.lineTo(screenPoint1.x, screenPoint1.y);

		// update starting point to next position
		projectedPoint0 = projectedPoint1;
		screenPoint0.x = screenPoint1.x;
		screenPoint0.y = screenPoint1.y;
	}

	canvas.drawPath(mPath, mPaint);
}
 
Example #7
Source File: MyLocationOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public MyLocationOverlay(final Context pContext, final MapView pMapView) {
	super(pContext, pMapView);
}