2012-01-27 23 views
1

我對android非常陌生。我正在開發一款使用Google地圖顯示當前位置的應用程序。顯示網格視圖而不是地圖

我爲此應用程序生成了密鑰。但它不會顯示地圖,而是顯示網格視圖。


The following is the code..! 
//MActivity 


package velu.ndot.hosp; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 

import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.widget.SeekBar; 
import android.widget.TextView; 
import android.widget.Toast; 

public class HospitalActivity extends MapActivity { 

private LocationManager myLocationManager; 
private LocationListener myLocationListener; 
private TextView myLongitude, myLatitude; 

private MapView myMapView; 
private SeekBar myZoomBar; 

private MapController myMapController; 

private void CenterLocation(GeoPoint centerGeoPoint) 
{ 
    myMapController.animateTo(centerGeoPoint); 


    myLongitude.setText("Longitude: "+ 
    String.valueOf((float)centerGeoPoint.getLongitudeE6()/1000000) 
    ); 
    myLatitude.setText("Latitude: "+ 
    String.valueOf((float)centerGeoPoint.getLatitudeE6()/1000000) 
    ); 
}; 

private void SetZoomLevel() 
{ 
    int myZoomLevel = myZoomBar.getProgress()+1; 
    myMapController.setZoom(myZoomLevel); 
    Toast.makeText(this, 
    "Zoom Level : " + String.valueOf(myZoomLevel), 
    Toast.LENGTH_LONG).show(); 
}; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.newtab); 
    myMapView = (MapView)findViewById(R.id.mapview); 
    myLongitude = (TextView)findViewById(R.id.longitude); 
    myLatitude = (TextView)findViewById(R.id.latitude); 
    myZoomBar = (SeekBar)findViewById(R.id.zoombar); 

    myMapView.setSatellite(true); //Set satellite view 
    myMapController = myMapView.getController(); 
    SetZoomLevel(); 

    myLocationManager = (LocationManager)getSystemService(
    Context.LOCATION_SERVICE); 

    myLocationListener = new MyLocationListener(); 

    myLocationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER, 
    0, 
    0, 
    myLocationListener); 

    //Get the current location in start-up 
    //check LastKnownLocation, if not valid, skip it. 
    Location initLocation= 
    myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if(initLocation != null) 
    { 
    GeoPoint initGeoPoint = new GeoPoint(
    (int)(initLocation.getLatitude()*1000000), 
    (int)(initLocation.getLongitude()*1000000)); 
    CenterLocation(initGeoPoint); 
    } 
    myZoomBar.setOnSeekBarChangeListener(myZoomBarOnSeekBarChangeListener); 
} 

private SeekBar.OnSeekBarChangeListener myZoomBarOnSeekBarChangeListener = 
    new SeekBar.OnSeekBarChangeListener(){ 

    public void onProgressChanged(SeekBar seekBar, int progress, 
    boolean fromUser) { 
    // TODO Auto-generated method stub 
    SetZoomLevel(); 
    } 

    public void onStartTrackingTouch(SeekBar seekBar) { 
    // TODO Auto-generated method stub 

    } 

    public void onStopTrackingTouch(SeekBar seekBar) { 
    // TODO Auto-generated method stub 

    } 

}; 

private class MyLocationListener implements LocationListener{ 

    public void onLocationChanged(Location argLocation) { 
    // TODO Auto-generated method stub 
    GeoPoint myGeoPoint = new GeoPoint(
    (int)(argLocation.getLatitude()*1000000), 
    (int)(argLocation.getLongitude()*1000000)); 

    CenterLocation(myGeoPoint); 
    } 

    public void onProviderDisabled(String provider) { 
    // TODO Auto-generated method stub 
    } 

    public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 
    } 

    public void onStatusChanged(String provider, 
    int status, Bundle extras) { 
    // TODO Auto-generated method stub 
    } 
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
}; 


//Manifest file 

這是我Manifest.xml文件,我已經得到了允許與互聯網

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="velu.ndot.hosp" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-sdk android:minSdkVersion="8" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <application 
     android:theme="@android:style/Theme.Light" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".HospitalActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <uses-library android:required="true" android:name="com.google.android.maps"> </uses-library> 
    </application> 
</manifest> 

//Layout 

我的佈局設計..!

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
    <TextView 
    android:id="@+id/longitude" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Longitude:" 
    /> 
    <TextView 
    android:id="@+id/latitude" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Latitude:" 
    /> 
    <SeekBar 
    android:id="@+id/zoombar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:max="20" 
    android:progress="0"/> 
</LinearLayout> 
<com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:clickable="false" 
    android:apiKey="key**********************" 
/> 
</LinearLayout> 

回答