0
서버에서 현재 주소를로드하는지도가 있습니다. MapReady에서 사용하고 초기화되기 전에 서버에서 첫 번째 위치를로드하고 위치를 확대합니다. 나는 앱이 매 10 초마다 서버에서 주소를 읽고 위치를 매핑하기를 원한다. 나는 이전 마커를 제거하고 서버의 값에서 새로운 마커를 추가하고 여전히 위치를 확대 할 수있는 MapReady에 붙어 있습니다. this과 같은 튜토리얼은별로 도움이되지 않았습니다. 아래는 MapReady에 관한 것입니다.안드로이드 서버에서 마커를 10 초마다 움직이게하는 방법
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(),
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.setTrafficEnabled(true);
mMap.setIndoorEnabled(true);
mMap.setBuildingsEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
geocoder = new Geocoder(getActivity());
try {
ArrayList<Address> current_adresses = (ArrayList<Address>) geocoder.getFromLocationName(current_location, 1);
for(Address add : current_adresses){
if (current_adresses != null) {//Controls to ensure it is right address such as country etc.
current_longitude = add.getLongitude();
current_latitude = add.getLatitude();
}
}
ArrayList<Address> to_adresses = (ArrayList<Address>) geocoder.getFromLocationName(destination, 1);
for(Address add : to_adresses){
if (to_adresses != null) {//Controls to ensure it is right address such as country etc.
to_longitude = add.getLongitude();
to_latitude = add.getLatitude();
}
}
} catch (IOException e) {
e.printStackTrace();
}
location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
if (location != null)
{
mMap.addMarker(new MarkerOptions()
.position(new LatLng(current_latitude, current_longitude))
.title(first_name + ", " + vehicle)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pickup)));
mMap.addMarker(new MarkerOptions()
.position(new LatLng(to_latitude, to_longitude))
.title("Destination")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.office_building)));
CameraPosition cameraPosition= new CameraPosition.Builder()
.target(getCenterCoordinate())
.zoom(13)
.build();
CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(cameraPosition);
mMap.animateCamera(camUpd3);
//AsyncTask to get new address
getTransporterLocation();
/**
*
* I want to set a timer with the AsyncTask inside,
*
* remove the previous marker, convert the new address to lat and long
*
* map the marker and zoom in
*
*/
}
}