I'm doing a game on android with maps. I have 3 key points that are to be reached, each point has its marker and its coordinates, this works well, now what I do not get is that when I am a few meters away from one of the marker I stop the music in the background that I have and another one starts, who says music says something else.
I put you as I have a marker:
LatLng latLng = new LatLng(42.237439, -8.714226);
int radius = 10;
CircleOptions circleOptions = new CircleOptions()
.center(latLng)
.radius(radius)
.strokeColor(Color.parseColor("#0D47A1"))
.strokeWidth(4)
.fillColor(Color.parseColor("#AF4046FF"));
Circle circle = mMap.addCircle(circleOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
mMap.addMarker(new MarkerOptions()
.position(latLng)
.title("Mision 1.")
.snippet("Fundador: user")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.sound1)));
mMap.setOnInfoWindowClickListener(this);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
Location location1p = new Location("mision1");
location1p.setLatitude(42.237439);
location1p.setLongitude(-8.714226);
distancia1 = locationGPS.distanceTo(location1p);
lblPista.setText("Mts a mision1: "+distancia1);
distance1 is declared as float in the main
As you can see I have declared the marker with its circle and the distanceTo () that would be to determine from my current position how much would remain to reach that point in meters I suppose. If I do a method with an if saying "if distance1 is less than or equal to 10 for the background music and plays this":
private void localizacionPistas() {
if(distancia1 <= 10){
musicafondo.stop();
guerra.start();
}
}
What is wrong so that it does not work?