I am developing one application in that I show the current location with red and surrounding location with HUE_AZURE colors, now I try to change both colors with HUE_GREEN(green), when I click on the marker, I wrote the code, but it does not work correctly. When I click on the marker, the map returns to its original position and changes color only once, this is my problem.
my code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map_when_login);
_googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapId)).getMap();
LocationManager service = (LocationManager)getSystemService(LOCATION_SERVICE);
boolean enableGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean enableWiFi= service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.e("GPS",""+enableGPS);
service = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, true);
service.requestLocationUpdates(provider, 0, 0, this);
if(_googleMap==null){
Toast.makeText(getApplicationContext(), "Google Map Not Available",
Toast.LENGTH_LONG).show();
}
}
@Override
public void onLocationChanged(Location location) {
this);
ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>)
getIntent().getSerializableExtra("arrayList");
if(location!=null){
latitude = location.getLatitude();
langitude = location.getLongitude();
LatLng latlang = new LatLng(latitude, langitude);
myPosition = new LatLng(latitude, langitude);
}
if(arl.size()!=0){
for(int j = 0;j<arl.size();j++){
String lat =arl.get(j).get("lat").toString();
String lng =arl.get(j).get("lng").toString();
if ( !lat.trim().equals("") && !lng.trim().equals("") )
{
double Hlat = Double.parseDouble(lat.trim());
double Hlong= Double.parseDouble(lng.trim());
dabaseLocations =new LatLng(Hlat, Hlong);
getOtherLocation(dabaseLocations);
getCurrentLocation(myPosition);
}
}
}
else{
getCurrentLocation(myPosition);
}
_googleMap.setOnMarkerClickListener(this);
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
private boolean getOtherLocation(LatLng location){
_googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,10));
mCustomerMarker = _googleMap.addMarker(new MarkerOptions()
.position(location)
.title("other")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.flat(true));
return true;
}
private boolean getCurrentLocation(LatLng location){
_googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,10));
currentMarker=_googleMap.addMarker(new
MarkerOptions().position(location).title(TITILE));
return true;
}
@Override
public boolean onMarkerClick(final Marker arg0) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
ShowMapWhenLoginActivity.this);
alertDialogBuilder.setTitle("Favourate Location");
alertDialogBuilder
.setMessage("Is it Your favourate location")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
if(getCurrentLocation(myPosition)){
_googleMap.addMarker(new MarkerOptions()
.position(myPosition)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
.flat(true));
Toast.makeText(getApplicationContext(),
"Marker Clicked: " + a
rg0.getPosition(), Toast.LENGTH_LONG)
.show();
}
else{
_googleMap.addMarker(new MarkerOptions()
.position(dabaseLocations)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
.flat(true));
}
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
return true;
}
source
share