Skip to content

Commit

Permalink
#25 : Removing bug while adding markers
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkit4tech committed Jan 11, 2017
1 parent 934c8d2 commit 799821e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PrivyMapsActivity extends ActionBarActivity implements OnMapReadyCa
private GoogleMap mMap;
private Context mContext;
private CameraPosition MY_LOCATION_CAMERA_POS;
private HashMap<Integer,MarkerData> universalMarkers;
private HashMap<String,MarkerData> universalMarkers;

// My location
private LocationData myLocationData;
Expand All @@ -44,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_privy_maps);

mContext = this;
universalMarkers = new HashMap<>();

// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
Expand Down Expand Up @@ -172,7 +173,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

private void markNearbyPrivys(LatLng myLocation){
universalMarkers = new HashMap<>();
new RequestData(mContext,mMap,universalMarkers,myLocation).getMarkerData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
Expand Down Expand Up @@ -43,9 +45,9 @@ public class RequestData {
private String PLACE = "place";
private String NEARBY = "nearbysearch";
private String TYPE = "json";
private HashMap<Integer, MarkerData> hm;
private HashMap<String, MarkerData> hm;

public RequestData(Context mContext, GoogleMap mMap, HashMap<Integer, MarkerData> universalMarkerHashMap, LatLng myLocation) {
public RequestData(Context mContext, GoogleMap mMap, HashMap<String, MarkerData> universalMarkerHashMap, LatLng myLocation) {
this.myLocation = myLocation;
this.mContext = mContext;
this.mMap = mMap;
Expand Down Expand Up @@ -84,16 +86,17 @@ public void onResponse(String response) {
private void addMarkers(PrivyPost post) {
for (MarkerData data : post.getResults()) {
Log.d(DEBUG, data.toString());
Marker temp = mMap.addMarker(new MarkerOptions().position(new LatLng(data.getGeometry().getLocation().getLat(), data.getGeometry().getLocation().getLng())).title(data.getName()));
hm.put(temp.hashCode(), data);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE);
Marker temp = mMap.addMarker(new MarkerOptions().position(new LatLng(data.getGeometry().getLocation().getLat(), data.getGeometry().getLocation().getLng())).title(data.getName()).icon(bitmapDescriptor));
hm.put(temp.getId(), data);
}

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
//testing
if (hm.containsKey(marker.hashCode()))
Toast.makeText(mContext, hm.get(marker.hashCode()).getName(), Toast.LENGTH_SHORT).show();
if (hm.containsKey(marker.getId()))
makeToast(mContext, hm.get(marker.getId()).getName());
else
marker.remove();
return false;
Expand Down

0 comments on commit 799821e

Please sign in to comment.