-1
我無法將當前位置傳遞給我的LatLng變量以顯示在我的谷歌地圖上。我不知道如何從我的位置偵聽器方法中的我的覆蓋語句傳遞值。我試圖實現一個應用程序,只需獲取GPS座標並在地圖上放置一個標記。我的應用中的GPS位置
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
//obtain location
listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
double lat = location.getLatitude();
double lng = location.getLongitude();
LatLng appoint = new LatLng(lat,lng);
return appoint;
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
};
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
double lat = 34.014783;
double lng = -84.571381;
// Add a marker in Appoint from database and move the camera
LatLng appoint = new LatLng(lat,lng);
mMap.addMarker(new MarkerOptions().position(appoint).title("Where the wild gays are"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(appoint));`
嘗試創建方法並從您的onlocationchanged方法傳遞lat和long方法 –