0
在這種情況下,地圖出現在我正在嘗試製作的應用程序上,但是當應用程序打開時,文件夾不會出現在當前位置,而是出現在Sout大西洋中。有沒有辦法在應用程序打開時調出當前位置?如何在應用程序啓動時獲取當前位置?
這裏是我的代碼:
public class GmapFragment extends Fragment implements OnMapReadyCallback,
ActivityCompat.OnRequestPermissionsResultCallback,
LocationListener
{
GoogleMap mMap;
GoogleApiClient mGoogleApiClient;
Location mLastLocation;
double longitude;
double latitude;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_gmaps, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MapFragment fragment = (MapFragment) getChildFragmentManager().findFragmentById(R.id.map);
fragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
LocationManager locManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
boolean network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Location location;
if(network_enabled){
location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(location!=null){
longitude = location.getLongitude();
latitude = location.getLatitude();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(-7.0559935,110.4320226))
.title("Kos Munyiq"));
mMap.addMarker(new MarkerOptions()
.position(new LatLng(-7.0500666,110.4264657))
.title("Kos Pos"));
mMap.animateCamera(CameraUpdateFactory.zoomTo(0));
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setMapToolbarEnabled(false);
}
}
}
@Override
public void onLocationChanged(Location location) {
}
}
很抱歉,如果有什麼問題,我的問題。
謝謝你試圖幫助我,我試圖改變代碼相應的解釋。地圖出現,但仍在南大西洋海域,當前位置按鈕消失。我做了什麼有什麼問題? – Plokodot