Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate()");
    setContentView(R.layout.map);
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapOverlays = mapView.getOverlays();
    pushPinMarker = this.getResources().getDrawable(R.drawable.ic_icon_map_marker);
    itemizedoverlay = new ObjectsItemizedOverlay(pushPinMarker, mapView);
    itemizedoverlay.setDestino(BikesDataActivity.class);
    userLocationMarker = this.getResources().getDrawable(R.drawable.ic_icon_user_location);
    userOverlay = new userItemizedOverlay(userLocationMarker);
    dndzgzApp = ((DndZgzApplication) this.getApplication());
    JSONArray listJSON = dndzgzApp.getBikesList();
    for (int i = 0; i < listJSON.length(); i++) {
      try {
        bikesArrayList.add((JSONObject) listJSON.get(i));
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
    Log.i(TAG, "bikesArrayList: " + bikesArrayList.size());

    runnableBikes =
        new Runnable() {
          @Override
          public void run() {
            paintObjects();
          }
        };

    Thread thread = new Thread(null, runnableBikes, "PintarPuntosMapa");
    thread.start();
    progressDialog =
        ProgressDialog.show(
            BikesMapActivity.this,
            getText(R.string.espere),
            getText(R.string.pintando_puntos),
            true);
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    locationListener =
        new LocationListener() {
          public void onLocationChanged(Location location) {
            showUserMarker(location);
            // Log.i(TAG, "LocationChanged");
          }

          public void onStatusChanged(String provider, int status, Bundle extras) {}

          public void onProviderEnabled(String provider) {
            requestLocations();
          }

          public void onProviderDisabled(String provider) {
            removeRequestLocation();
          }
        };
    trackUserLocation();
  }