我正在尝试在活动中显示地图,但我无法显示切片。这是我的代码:
package com.codendo.androidapps.studhouseaarhus;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class LocationActivity extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
MapOverlay itemizedoverlay = new MapOverlay(drawable, this);
GeoPoint point = new GeoPoint(19240000,-99120000);
String lbl_title = getResources().getString(R.string.lbl_location_title);
String lbl_text = getResources().getString(R.string.lbl_location_text);
OverlayItem overlayitem = new OverlayItem(point, lbl_title, lbl_text);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
setTitleFromActivityLabel(R.id.title_text);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
/**
*/
// Click Methods
/**
* Handle the click on the home button.
*
* @param v View
* @return void
*/
public void onClickHome (View v)
{
goHome (this);
}
/**
* Handle the click on the search button.
*
* @param v View
* @return void
*/
public void onClickSearch (View v)
{
// startActivity (new Intent(getApplicationContext(), SearchActivity.class));
}
/**
* Handle the click on the About button.
*
* @param v View
* @return void
*/
public void onClickAbout (View v)
{
startActivity (new Intent(getApplicationContext(), AboutActivity.class));
}
/**
*/
// More Methods
/**
* Go back to the home activity.
*
* @param context Context
* @return void
*/
public void goHome(Context context)
{
final Intent intent = new Intent(context, HomeActivity.class);
intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity (intent);
}
/**
* Use the activity label to set the text in the activity's title text view.
* The argument gives the name of the view.
*
* <p> This method is needed because we have a custom title bar rather than the default Android title bar.
* See the theme definitons in styles.xml.
*
* @param textViewId int
* @return void
*/
public void setTitleFromActivityLabel (int textViewId)
{
TextView tv = (TextView) findViewById (textViewId);
if (tv != null) tv.setText (getTitle ());
} // end setTitleText
}
布局:
<?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="wrap_content"
>
<LinearLayout style="@style/TitleBar" android:id="@+id/title_container">
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_home"
android:src="@drawable/title_home"
android:onClick="onClickHome" android:id="@+id/title_logo" />
<ImageView style="@style/TitleBarSeparator" />
<TextView style="@style/TitleBarText" android:id="@+id/title_text"/>
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_about"
android:src="@drawable/title_about"
android:onClick="onClickAbout" />
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_search"
android:src="@drawable/title_search"
android:onClick="onClickSearch" />
</LinearLayout>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0LzZr3xWzmR-_Y5oqCuTx5DDPo1w_LUH7WZn0uw"
/>
</LinearLayout>
以下是我宣布使用Google地图的清单文件部分:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
我知道这里有一些类似的问题,我已经阅读过它们并没有发现任何对我有用的东西。
这是我到目前为止所做的:
答案 0 :(得分:1)
您的<uses-permission>
元素必须位于<application>
元素之外,而不是在内部。