응용 프로그램이 실행되는 동안 내 Google지도 활동에 마커를 구현하려고했습니다. 일부 미리 정의 된 "위치"개체가 있으며 사용자의 "현재 위치"에 마커가 있습니다.앱 실행 중지도에 마커 추가 성공하지 못했습니다.
, 더 마커가 추가되지 얻을 (하나에서 거기에 내가 위치 개체의 마커가 표시되어야하는 현재 위치의 range
을 변경려고하는 SeekBar
를 사용하지만, SeekBar
변경에 아무 일도 발생하지 않습니다 현재 위치). LatLng
들에 대한
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.
OnConnectionFailedListener, OnSeekBarChangeListener {
private GoogleApiClient googleApiClient;
private SeekBar rangeSeekBar;
private GoogleMap mMap;
private Intent intent;
private Location currentLocation;
private Location[] locations;
private double range;
Location locationOne;
Location locationTwo;
Location locationThree;
Location locationFour;
Location locationFive;
Location locationSix;
Location locationSeven;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
locationOne = new Location("");
locationTwo = new Location("");
locationThree = new Location("");
locationFour = new Location("");
locationFive = new Location("");
locationSix = new Location("");
locationSeven = new Location("");
locationOne.setLatitude(10.1399);
locationOne.setLongitude(76.1784);
locationTwo.setLatitude(10.2244);
locationTwo.setLongitude(76.1978);
locationThree.setLatitude(9.6175);
locationThree.setLongitude(76.4301);
locationFour.setLatitude(9.5987);
locationFour.setLongitude(76.3116);
locationFive.setLatitude(9.6175);
locationFive.setLongitude(76.4301);
locationSix.setLatitude(9.6737);
locationSix.setLongitude(76.5610);
locationSeven.setLatitude(15.5152);
locationSeven.setLongitude(73.8565);
locations = new Location[]{
locationOne,
locationTwo,
locationThree,
locationFour,
locationFive,
locationSix,
locationSeven
};
rangeSeekBar = (SeekBar)findViewById(R.id.rangeSeekBar);
rangeSeekBar.setProgress(0);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
protected void onStop() {
super.onStop();
googleApiClient.disconnect();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng india = new LatLng(20.5937, 78.9629);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(india, 5));
if(googleApiClient==null){
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
googleApiClient.connect();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
if(ContextCompat.checkSelfPermission(MapsActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MapsActivity.this,new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},1);
} else {
currentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
LatLng currentLoc = new LatLng(currentLocation.getLatitude(),currentLocation.getLongitude());
mMap.addMarker(new MarkerOptions().position(currentLoc).title("Your current location"));
}
addingMarkersInRange(0);
}
public void addingMarkersInRange(double range){
for(int i=0;i<locations.length;i++){
if(currentLocation.distanceTo(locations[i])<range) {
LatLng tempLatLng = new LatLng(locations[i].getLatitude(), locations[i].getLongitude());
mMap.addMarker(new MarkerOptions().position(tempLatLng));
mMap.moveCamera(CameraUpdateFactory.newLatLng(tempLatLng));
}
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
addingMarkersInRange(rangeSeekBar.getProgress()*700000);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
정말 오류가 표시됩니까? 마커가 보이지 않습니까? –
@Kirankumar Zinzuvadia 예 죄송합니다. 마커가 표시되지 않습니다. 오류가 없습니다. – Ryuzaki