Android Open Source - hacktoolkit-android_lib Mapper






From Project

Back to project page hacktoolkit-android_lib.

License

The source code is released under:

MIT License

If you think the Android project hacktoolkit-android_lib 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.hacktoolkit.android.maps;
//w w w . j av  a  2 s.c  o m
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;

public class Mapper {
  public static Mapper _instance;
  public static Mapper getInstance(GoogleMap googleMap) {
    if (Mapper._instance == null && googleMap != null) {
      Mapper._instance = new Mapper(googleMap);
    }
    return Mapper._instance;
  }

  private GoogleMap googleMap;
  private MarkerOptions currentLocationMarker;
    
  public Mapper(GoogleMap googleMap) {
    this.googleMap = googleMap;
    // TODO: not working for some reason?
//    UiSettings settings = googleMap.getUiSettings();
//    settings.setMyLocationButtonEnabled(true);
  }
  
  public boolean updateMap(String label, double latitude, double longitude) {
    boolean updated = false;
    if (googleMap != null) {
      updateCurrentLocationMarker(label, latitude, longitude);

      LatLngBounds.Builder builder = new LatLngBounds.Builder();
//      for each (Marker m : markers) {
//        builder.include(m.getPosition());
//      }
      builder.include(currentLocationMarker.getPosition());
      LatLngBounds bounds = builder.build();

      int padding = 0; // offset from edges of the map in pixels
      CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
      //googleMap.animateCamera(cameraUpdate);
      googleMap.moveCamera(cameraUpdate);
      googleMap.moveCamera(CameraUpdateFactory.zoomTo(10));
      updated = true;
    }
    return updated;
  }
  
  private void updateCurrentLocationMarker(String label, double latitude, double longitude) {
    if (currentLocationMarker == null) {
      currentLocationMarker = new MarkerOptions()
      .position(new LatLng(latitude, longitude))
      .title(label);
      googleMap.addMarker(currentLocationMarker);
    } else {
      LatLng coord = new LatLng(latitude, longitude);
      currentLocationMarker.position(coord);
    }
  }
}




Java Source Code List

com.hacktoolkit.android.activities.HTKSplashScreenActivity.java
com.hacktoolkit.android.adapters.HTKContactsAdapter.java
com.hacktoolkit.android.api_helpers.FacebookHelper.java
com.hacktoolkit.android.api_helpers.HTKCallback.java
com.hacktoolkit.android.api_helpers.ParseHelper.java
com.hacktoolkit.android.constants.GeoConstants.java
com.hacktoolkit.android.constants.StringConstants.java
com.hacktoolkit.android.constants.TimeConstants.java
com.hacktoolkit.android.constants.UnitConstants.java
com.hacktoolkit.android.fragments.ContactsFragment.java
com.hacktoolkit.android.maps.MapUtils.java
com.hacktoolkit.android.maps.Mapper.java
com.hacktoolkit.android.models.HTKContact.java
com.hacktoolkit.android.user.HTKUser.java
com.hacktoolkit.android.utils.BitmapUtils.java
com.hacktoolkit.android.utils.ContactsUtils.java
com.hacktoolkit.android.utils.FileUtils.java
com.hacktoolkit.android.utils.HTKUtils.java
com.hacktoolkit.android.utils.SystemUiHiderBase.java
com.hacktoolkit.android.utils.SystemUiHiderHoneycomb.java
com.hacktoolkit.android.utils.SystemUiHider.java