예제 #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapV = (MapView) findViewById(R.id.mapView);

    mapV.displayZoomControls(true);
    mapV.setBuiltInZoomControls(true);
    mapV.setSaveEnabled(true);

    initlocation.setLatitude(0.1);
    initlocation.setLongitude(0.1);

    GeoP =
        new GeoPoint(
            (int) (initlocation.getLatitude() * 1E6), (int) (initlocation.getLongitude() * 1E6));

    posOverlay = new MapOverlay();
    List<Overlay> overlays = mapV.getOverlays();
    overlays.add(posOverlay);

    mControl = mapV.getController();
    mControl.animateTo(GeoP);
    mControl.setZoom(5);

    Bitmap iss = BitmapFactory.decodeResource(getResources(), R.drawable.iss);
    Bitmap logo = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
    Bitmap logotext = BitmapFactory.decodeResource(getResources(), R.drawable.logotext);
    Bitmap tracker = BitmapFactory.decodeResource(getResources(), R.drawable.isstracker);
    posOverlay.SetImages(iss, logo, logotext, tracker);
    posOverlay.setLocation(initlocation);

    if (CheckNetwork(getApplicationContext())) {
      startUpdateTimer();
    } else {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage(
          "No data connection found, please check you have a mobile data connection or wifi enabled.");
      builder.setNegativeButton(
          "Quit",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              dialog.cancel();
              finish();
            }
          });
      AlertDialog alert = builder.create();

      alert.show();
    }
  }
예제 #2
0
  public void init() {

    LogManager.d("init");

    geoBeijing = new GeoPoint((int) (39.932 * 1000000), (int) (116.461 * 1000000));
    mDefaultCurrentLocation =
        new GeoPoint((int) (41.892910 * 1000000), (int) (12.48251990 * 1000000));

    mapView = (MapView) findViewById(R.id.map_view);
    map_view_enable = findViewById(R.id.map_view_enable);
    mapView.getLayoutParams().height = BaseActivity.screen_height * 1 / 2;
    map_view_enable.getLayoutParams().height = BaseActivity.screen_height * 1 / 2;
    mapView.setOnTouchListener(this);
    mapView.setSaveEnabled(true);
    mapView.setBuiltInZoomControls(false);

    mapCon = mapView.getController();
    mapCon.setZoom(defaultZoom);

    // geo = new Geocoder(getContext(), Locale.CHINA);
    mapCon.setCenter(mDefaultCurrentLocation);
    mapView.setTraffic(false);
    mapView.setSatellite(false);

    mPopView = (ViewGroup) mapActivity.getLayoutInflater().inflate(R.layout.map_popover, null);

    // MapActivity mapActivity = (MapActivity)getContext();
    // WindowManager windowManager = mapActivity.getWindowManager();
    // int width = windowManager.getDefaultDisplay().getWidth();

    mapView.addView(
        mPopView,
        new MapView.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            null,
            MapView.LayoutParams.TOP_LEFT));
    mPopView.setVisibility(View.GONE);
    overlays = mapView.getOverlays();

    Drawable currentLocationMarker =
        this.getContext().getResources().getDrawable(R.drawable.user_location);
    mCurrentLocationOverlay = new MapItemizedOverlay(currentLocationMarker, this);
    mCurrentLocationOverlay.showPop = false;
    Drawable search = this.getContext().getResources().getDrawable(R.drawable.pin);

    bankOverlay = new MapItemizedOverlay(search, this);

    overlays.add(mCurrentLocationOverlay);
    overlays.add(bankOverlay);

    locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);

    mLocationListener1 =
        new LocationListener() {
          public void onLocationChanged(Location location) {
            Log.e(
                "Location",
                "GPSListener  "
                    + "latitude:"
                    + Double.toString(location.getLatitude())
                    + " longtitude:"
                    + Double.toString(location.getLongitude())
                    + " from:"
                    + location.getProvider());
            if (isBetterLocation(location, mCurrentLocation)) {
              setCurrentLocation(location);
              if (mMapShowingForLocationUpdate) {
                addCurrentLocationOverlay();
              }
            }
          }

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

          public void onProviderEnabled(String provider) {}

          public void onProviderDisabled(String provider) {}
        };

    mLocationListener2 =
        new LocationListener() {
          private boolean mFirstLaunch;

          public void onLocationChanged(Location location) {
            Log.e(
                "Location",
                "NetworkListener  "
                    + "latitude:"
                    + Double.toString(location.getLatitude())
                    + " longtitude:"
                    + Double.toString(location.getLongitude())
                    + " from:"
                    + location.getProvider());
            if (isBetterLocation(location, mCurrentLocation)) {
              setCurrentLocation(location);
              if (mMapShowingForLocationUpdate) {
                addCurrentLocationOverlay();
              }
            }
            if (mFirstLaunch == true) {
              mFirstLaunch = false;
              locationManager.removeUpdates(mLocationListener2);
            }
          }

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

          public void onProviderEnabled(String provider) {}

          public void onProviderDisabled(String provider) {}
        };
    myLocation = (ImageButton) findViewById(R.id.my_location);
    mapLayer = (ImageButton) findViewById(R.id.map_layer);
    showItems = (ImageButton) findViewById(R.id.show_items);
    searchButton = (ImageButton) findViewById(R.id.search_btn);
    searchEdt = (EditText) findViewById(R.id.search_input);
    distance_input = (EditText) findViewById(R.id.distance_input);
    if (App.app.initValue) {

      searchEdt.setText("05387");

      searchEdt.setText("via del tintoretto,200,roma");
    }

    searchButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // BaseMapActivity baseactivity = (BaseMapActivity)getContext();
            // baseactivity.hideKeyboard(searchButton);
            KeyBoardUtils.hideSoftInputFromWindow(mapActivity, searchEdt.getWindowToken());
            ProgressOverlay progressOverlay = new ProgressOverlay(getContext());
            progressOverlay.show(
                "searching...",
                new OnProgressEvent() {

                  @Override
                  public void onProgress() {

                    // Locale locale =
                    // getResources().getConfiguration().locale;

                    final String keyText = searchEdt.getText().toString();
                    searchGeoPoint = searchLocation(keyText);
                    if (searchGeoPoint != null) {
                      searchBarch(keyText);
                    }
                  }
                });
          }
        });

    mapLayer.setOnClickListener(
        new OnClickListener() {

          int i;

          @Override
          public void onClick(View v) {

            i++;
            int value = i % 2;
            switch (value) {
              case 0:
                mapView.setTraffic(false);
                mapView.setSatellite(false);
                break;
              case 1:
                mapView.setTraffic(false);
                mapView.setSatellite(true);

                break;
            }
          }
        });
    showItems.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (enter_distance_layout.getVisibility() == View.VISIBLE) {
              enter_distance_layout.setVisibility(View.GONE);
            } else {

              enter_distance_layout.setVisibility(View.VISIBLE);
            }
          }
        });
    myLocation.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            goToMyLocation();
          }
        });
    handler = new Handler();
    enter_distance_layout = (ViewGroup) findViewById(R.id.enter_distance_layout);
  }