package com.test.map;
import android.location.Location;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import com.google.android.maps.*;
public class Gmap extends MapActivity {
static final int INITIAL_ZOOM_LEVEL = 13;
//初始位置
static final int INITIAL_LATITUDE = 24150000;
static final int INITIAL_LONGITUDE = 120684000;
MapController mc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//程式外觀
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
//取得位置
//顯示地圖
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(INITIAL_ZOOM_LEVEL);
mc.setCenter(new GeoPoint(INITIAL_LATITUDE,INITIAL_LONGITUDE));
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
public void onLocationChanged(Location location) {
GeoPoint gp =
new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
mc.animateTo(gp);
}
}
以上是我目前的程式碼
我想問的是要如何取得位置
之前有打這段程式碼:
LocationManager mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
可是在模擬器上run時又不行
又找不出什麼錯誤(註:在打那段程式碼時只有加一些不會打擾原程式碼的內容)
所以請教一下大大們
定位那段程式碼該填什麼?
或者是該修改甚麼?