我試圖創建一個應用程序,將通過GPS獲取用戶位置,顯示谷歌地圖中的用戶位置,然後更新一定的時間/運動後。android - eclipse:顯示谷歌地圖使用座標獲得使用gps
我目前有一個應用程序可以通過gps獲取用戶位置,並且每10米/ 10,000毫秒更新一次,但是目前它所做的只是顯示座標是什麼。我已經設置好連接到谷歌地圖,但是現在只需將地圖設置爲我手動輸入的一些座標。
我如何得到它,所以地圖將顯示基於通過gps獲得的座標的位置?
任何幫助將不勝感激,我對這一切都很新!
編輯:繼承人我的代碼到目前爲止!
package com.android.basicmap;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.GeoPoint;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
public class BasicMapActivity extends MapActivity {
private MapView mapView;
private MapController mapController;
private LocationManager locationManager;
private LocationListener locationListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
mapController.setZoom(16);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private class GPSLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
Toast.makeText(getBaseContext(),
"Latitude: " + location.getLatitude() +
" Longitude: " + location.getLongitude(),
Toast.LENGTH_SHORT).show();
mapController.animateTo(point);
mapController.setZoom(16);
mapView.invalidate();
}
}
}
}
嗨,歡迎來到Stack Overflow!如果您包含一些_relevant_代碼段,您將有更好的機會讓您的問題得到解答。例如,你提到你有位置更新工作,但沒有地圖更新部分。從您的Map類中包含_relevant_片段可能是一個好主意。 – 2012-02-08 17:59:34