大家好:
想請教我用eclipse寫android
目前想加入google map,但加入後地圖開起都是空白.....
以下程式碼.java:
public class ExGPS01Activity extends MapActivity implements LocationListener {
private MapView map;
private MapController mapController;
private LocationManager locMgr;
String bestProv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ex_gps01);
map = (MapView) findViewById(R.id.map) ; //取得 google map 元件
map.setBuiltInZoomControls(true); // 地圖縮放和拖曳
map.setSatellite(true); // 設定地圖檢示模式:衛星地圖
mapController = map.getController();
mapController.setZoom(17); //設定放大倍率1(地球)-21(街景)
locMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProv = locMgr.getBestProvider(criteria, true);
}
@Override
public void onLocationChanged(Location location) {
GeoPoint gp=new GeoPoint(
(int) (location.getLatitude() * 1000000),
(int) (location.getLongitude() * 1000000) );
mapController.animateTo(gp); // 指定地圖現在位置
String x="緯=" + Double.toString(location.getLatitude());
String y="經=" + Double.toString(location.getLongitude());
Toast.makeText(ExGPS01Activity.this,x + "\n" + y, Toast.LENGTH_LONG).show();
}
@Override
protected void onResume() {
super.onResume();
// 如果GPS或網路定位開啟,更新位置
if (locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER) || locMgr.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locMgr.requestLocationUpdates(bestProv, 6000, 1, this);
}
}
@Override
protected void onPause() {
super.onPause();
locMgr.removeUpdates(this);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Criteria criteria = new Criteria();
bestProv = locMgr.getBestProvider(criteria, true);
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
xml:
<com.google.android.maps.MapView android:id="@+id/map"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:clickable="true"
android:apiKey="AIzaSyBfO9hOVD142oYQIMYEMIaSZyjyUUY8lW8" />
權限也都有加,但開起來就是這樣
我也有去google map 申請權限,但還是不行...
請各位大大幫忙,告訴我有哪你弄錯了
謝謝
祝大家新年快樂囉~!!