2011-05-18 74 views
1

即時嘗試使用谷歌地圖在我的Android應用程序。在Android模擬器中顯示谷歌地圖

我已經添加了兩個權限的用戶:INTERNET和ACCESS_FINE_LOCATION「 也: ‘使用庫機器人:名字=’com.google.android.maps」 這裏是我的活動顯示地圖:

public class SportEventActivity extends MapActivity { 
    private MapController mapController; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.sportevent); 
     Bundle extras = getIntent().getExtras(); 
     if (extras != null) { 
      // Reads the parameters to this view 
      String sportName = extras.getString(Utility.SPORT_NAME); 
      String venueName = extras.getString(Utility.VENUE_NAME); 
      String startDate = extras.getString(Utility.START_DATE); 
      String endDate = extras.getString(Utility.END_DATE); 
      final String latitude = extras.getString(Utility.LATITUDE); 
      final String longitude = extras.getString(Utility.LONGITUDE); 
      TextView text1 = (TextView) findViewById(R.id.sedSportName); 
      text1.setText("Sport: " + sportName); 
      TextView text2 = (TextView) findViewById(R.id.sedVenue); 
      text2.setText("Venue: " + venueName); 
      TextView text3 = (TextView) findViewById(R.id.sedStartDate); 
      text3.setText("Start date: " + startDate); 
      TextView text4 = (TextView) findViewById(R.id.sedEndDate); 
      text4.setText("End date: " + endDate); 
      MapView mapView = (MapView) findViewById(R.id.mapview2); 
      mapView.setBuiltInZoomControls(true); 
      mapView.setStreetView(true); 
      this.mapController = mapView.getController(); 
      this.mapController.setZoom(16); 
      Double lat = getCoordinate(latitude) * 1E6; 
      Double lng = getCoordinate(longitude) * 1E6; 
      mapController.setCenter(new GeoPoint(lat.intValue(), lng.intValue())); 

     } 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     return false; 
    } 

    private Double getCoordinate(String coordinate) { 
     return Double.parseDouble(coordinate); 
    } 
} 

,你也可以找到與此相關的活動佈局代碼:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:stretchColumns="1" android:id="@+id/sedLayout"> 

    <TableRow> 
    </TableRow> 

    <TableRow> 
     <TextView android:layout_column="1" android:padding="3dip" 
      android:text="Sport name" android:id="@+id/sedSportName" /> 
     <TextView android:gravity="right" android:padding="3dip" /> 
    </TableRow> 

    <TableRow> 
     <TextView android:layout_column="1" android:padding="3dip" 
      android:text="Venue" android:id="@+id/sedVenue" /> 
     <TextView android:gravity="right" android:padding="3dip" /> 
    </TableRow> 

    <TableRow> 
     <TextView android:padding="3dip" /> 
     <TextView android:padding="3dip" android:text="Start Date" 
      android:id="@+id/sedStartDate" /> 
    </TableRow> 

    <TableRow> 
     <TextView android:padding="3dip" /> 
     <TextView android:padding="3dip" android:text="End Date" 
      android:id="@+id/sedEndDate" /> 
     <TextView android:gravity="right" android:padding="3dip" /> 
    </TableRow> 
    <TableRow> 
     <TextView android:padding="3dip" /> 
     <View android:layout_height="2dip" android:background="#FF909090" />   
     <TextView android:padding="3dip" /> 
    </TableRow> 

    <TableRow> 
    </TableRow> 
    <com.google.android.maps.MapView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/mapview2" android:layout_width="fill_parent" 
      android:layout_height="fill_parent" android:clickable="true"    
      android:apiKey="0aULnfycQonb-l_B1QlcK8u4POo4_oKjnmqMU1Q" /> 
</TableLayout> 

我可以看到地圖,但問題是,當我看到地圖,它在地圖上顯示一個棋圖。我附上了截圖結果。如果任何機構爲什麼向我顯示帶有邊框的地圖,請給我一個解決方案。

here is the screen shot of

+0

怎麼樣的佈局? – aromero 2011-05-18 23:38:19

+0

這裏是佈局: – user261002 2011-05-19 00:02:20

+0

user261002 2011-05-19 00:02:26

回答

0

我想這是因爲你被膨脹的MapView您TableLayout內(但通過tablerow外)。我將整個事件包裝在一個垂直方向的RelativeLayout中,首先放置TableLayout,然後放置第二個mapview。

我重複了您的佈局,並沒有發現您遇到的問題。唯一的區別是我與中心的地圖座標:

m_mapView = (MapView) findViewById(R.id.mapview); 
m_mapView.setBuiltInZoomControls(true); 
m_mapView.setClickable(true); 

m_mapView.setStreetView(true); 
m_mapController = m_mapView.getController(); 
m_mapController.setZoom(16); 
m_mapController.setCenter(new GeoPoint((int)(47.975 * 1E6), (int)(17.056 * 1E6)));! 

如果您發佈座標串被解析並傳遞到setCenter我可以測試是否這就是問題所在。在這種情況下,這似乎是一個錯誤:

screenshot