Android Open Source - SDCrimeZone Circle Map Overlay






From Project

Back to project page SDCrimeZone.

License

The source code is released under:

Apache License

If you think the Android project SDCrimeZone listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.crimezone.sd;
//from   ww  w  .  j a  va 2s  .c  o  m
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class CircleMapOverlay extends Overlay {

  Context context;
  double mLat;
  double mLon;
  float radius;

  public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1 / Math.cos(Math
        .toRadians(latitude))));
  }

  public CircleMapOverlay(Context _context, double _lat, double _lon, float _radius) {
    context = _context;
    mLat = _lat;
    mLon = _lon;
    radius = _radius;
  }

  public void draw(Canvas canvas, MapView mapView, boolean shadow) {

    super.draw(canvas, mapView, shadow);

    Projection projection = mapView.getProjection();

    Point pt = new Point();

    GeoPoint geo = new GeoPoint((int) (mLat * 1e6), (int) (mLon * 1e6));

    projection.toPixels(geo, pt);

    float circleRadius = metersToRadius(radius * 1650, mapView, mLat);

    Paint innerCirclePaint;

    innerCirclePaint = new Paint();
    innerCirclePaint.setARGB(100, 150, 150, 180);
    innerCirclePaint.setAntiAlias(true);
    innerCirclePaint.setStyle(Style.FILL);
    
    Paint outerCirclePaint = new Paint();
    outerCirclePaint.setColor(0xFF000000);
    outerCirclePaint.setStyle(Style.STROKE);
    outerCirclePaint.setAntiAlias(true);
    outerCirclePaint.setStrokeWidth((float) 5.0);


    canvas.drawCircle((float) pt.x, (float) pt.y, circleRadius, innerCirclePaint);
    canvas.drawCircle((float) pt.x, (float) pt.y, circleRadius, outerCirclePaint);
  }
}




Java Source Code List

com.crimezone.sd.BccCodeEnum.java
com.crimezone.sd.CircleMapOverlay.java
com.crimezone.sd.CrimeMapOverlay.java
com.crimezone.sd.Data.java
com.crimezone.sd.SDCrimeMapActivity.java
com.crimezone.sd.SDCrimeSummaryActivity.java
com.crimezone.sd.SDCrimeSummaryWorker.java
com.crimezone.sd.SDCrimeZoneActivity.java
com.crimezone.sd.SDCrimeZoneApplication.java
com.crimezone.sd.SDPopulateCrimeListActivity.java
com.crimezone.sd.ShowCrimeMapActivity.java