android应用中的googlemap
我是Android的新手。很多天以来,我一直在努力使自己变得非常棒 基本谷歌地图应用程序,但尚未完成…:(android应用中的googlemap,android,google-maps,Android,Google Maps,我是Android的新手。很多天以来,我一直在努力使自己变得非常棒 基本谷歌地图应用程序,但尚未完成…:( 代码中没有错误,模拟器从终端正常运行,映射 钥匙也很好,但我还是看不到地图。当我运行 只显示应用程序网格,不显示地图。这是代码,可以吗 任何人都请帮助我 public class HelloGoogleMaps extends MapActivity { /** Called when the activity is first created. */ @Overrid
代码中没有错误,模拟器从终端正常运行,映射 钥匙也很好,但我还是看不到地图。当我运行 只显示应用程序网格,不显示地图。这是代码,可以吗 任何人都请帮助我
public class HelloGoogleMaps extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView =(MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
protected boolean isRouteDisplayed(){
return false;
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:layout_weight="1"
android:clickable="true"
android:apiKey="0fyF-qSuCtdQinoUGoFbLxZoTx10Tm-YV6m6A8g"
/>
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.GoogleMaps"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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"/>
<activity android:name=".HelloGoogleMaps"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<!--<activity android:name=".HelloGoogleMaps"
android:label="@string/app_name">-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
不知道哪里出了问题。我使用的是eclipse和android 1.6,你使用的是正确的Google地图键吗?如果你使用的是调试键,地图似乎不起作用 您可能必须在没有--debug标志的情况下重新生成密钥
也许这会有所帮助:常见的问题是您使用了错误的模拟器(即不是Google API模拟器)、导入错误、API密钥错误、在清单中没有权限、没有使用库等 我写了一本新手指南,看看
尝试在应用程序标记之外设置internet权限我认为问题在于您使用了错误的apk。您必须使用模拟器生成的apk(在我的例子中是eclipse),而不是使用选项“导出”生成的apk。我认为问题与用于导出apk的密钥与google maps api密钥不同有关。请尝试
PS:很抱歉我的英语不好。我最近经历了所有这些。我也尝试了所有提到的方法,但所有有效的方法都是- 确保您不是代理后的用户,并删除您在模拟器上所做的任何代理设置。存在一个错误,即谷歌地图无法在代理后的Android模拟器上运行。
**//Activty**
**// Activty**
public class MapsActivity extends MapActivity {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private MyOverlays itemizedoverlay;
private MyLocationOverlay myLocationOverlay;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main); // bind the layout to the activity
// Configure the Map
mapView = (MapView) findViewById(R.id.map_container);
mapView.setBuiltInZoomControls(true);
// mapView.setSatellite(true);
mapView.setStreetView(true);
mapController = mapView.getController();
mapController.setZoom(14); // Zoon 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {
mapView.getController().animateTo(myLocationOverlay.getMyLocation());
}
});
Drawable drawable = this.getResources().getDrawable(R.drawable.map);
itemizedoverlay = new MyOverlays(this, drawable);
createMarker();
}
protected boolean isRouteDisplayed() {
return false;
}
public class GeoUpdateHandler implements LocationListener {
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
createMarker();
mapController.animateTo(point); // mapController.setCenter(point);
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
private void createMarker() {
GeoPoint p = mapView.getMapCenter();
OverlayItem overlayitem = new OverlayItem(p, "", "");
itemizedoverlay.addOverlay(overlayitem);
if (itemizedoverlay.size() > 0) {
mapView.getOverlays().add(itemizedoverlay);
}
}
protected void onResume() {
super.onResume();
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
}
protected void onPause() {
super.onPause();
myLocationOverlay.disableMyLocation();
myLocationOverlay.disableCompass();
}
}
**//Class MyOvelays**
public class MyOverlays extends ItemizedOverlay<OverlayItem> {
private static int maxNum = 5;
private OverlayItem overlays[] = new OverlayItem[maxNum];
private int index = 0;
private boolean full = false;
private Context context;
private OverlayItem previousoverlay;
public MyOverlays(Context context, Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return overlays[i];
}
@Override
public int size() {
if (full) {
return overlays.length;
} else {
return index;
}
}
public void addOverlay(OverlayItem overlay) {
if (previousoverlay != null) {
if (index < maxNum) {
overlays[index] = previousoverlay;
} else {
index = 0;
full = true;
overlays[index] = previousoverlay;
}
index++;
populate();
}
this.previousoverlay = overlay;
}
protected boolean onTap(int index) {
OverlayItem overlayItem = overlays[index];
Builder builder = new AlertDialog.Builder(context);
builder.setMessage("This will end the activity");
builder.setCancelable(true);
builder.setPositiveButton("I agree", new OkOnClickListener());
builder.setNegativeButton("No, no", new CancelOnClickListener());
AlertDialog dialog = builder.create();
dialog.show();
return true;
};
private final class CancelOnClickListener implements
DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "You clicked yes", Toast.LENGTH_LONG)
.show();
}
}
private final class OkOnClickListener implements
DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "You clicked no", Toast.LENGTH_LONG).show();
}
}
}
//Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/map_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0PYAmXmindXBuvCvIFhCUC3y0GNjJKuFJHclkVw"
android:clickable="true"
android:focusable="true"
android:keepScreenOn="true"
/>
</RelativeLayout>
//Android.mainifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MapsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
公共类MapsActivity扩展了MapActivity{
专用地图控制器;
私有地图视图;
私人场所经理场所经理;
私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密私密;
私人我的位置我的位置;
创建公共void(Bundle){
super.onCreate(bundle);
setContentView(R.layout.main);//将布局绑定到活动
//配置地图
mapView=(mapView)findViewById(R.id.map\u容器);
mapView.SetBuilTinZoomControl(真);
//mapView.setSatellite(真);
mapView.setStreetView(真);
mapController=mapView.getController();
mapController.setZoom(14);//Zoon 1是世界视图
locationManager=(locationManager)getSystemService(Context.LOCATION\u服务);
locationManager.RequestLocationUpdate(locationManager.GPS_提供程序,0,
0,新的GeoUpdateHandler());
myLocationOverlay=新建myLocationOverlay(此为地图视图);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.runOnFirstFix(新的Runnable()文件){
公开募捐{
mapView.getController().animateTo(myLocationOverlay.getMyLocation());
}
});
Drawable Drawable=this.getResources().getDrawable(R.Drawable.map);
itemizedoverlay=新的MyOverlays(此为可绘制);
createMarker();
}
受保护的布尔值isRouteDisplayed(){
返回false;
}
公共类GeoUpdateHandler实现LocationListener{
已更改位置上的公共无效(位置){
intlat=(int)(location.getLatitude()*1E6);
int lng=(int)(location.getLongitude()*1E6);
地质点=新的地质点(纬度、液化天然气);
createMarker();
mapController.animateTo(点);//mapController.setCenter(点);
}
公共无效onProviderDisabled(字符串提供程序){
}
公共无效onProviderEnabled(字符串提供程序){
}
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
}
}
私有void createMarker(){
地理点p=mapView.getMapCenter();
OverlayItem OverlayItem=新的OverlayItem(p,“,”);
itemizedoverlay.addOverlay(overlayitem);
if(itemizedoverlay.size()>0){
mapView.getOverlays().add(ItemizeOverlay);
}
}
受保护的void onResume(){
super.onResume();
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
}
受保护的void onPause(){
super.onPause();
myLocationOverlay.disableMyLocation();
myLocationOverlay.disableCompass();
}
}
**//MyOvelays类**
公共类MyOverlays扩展了ItemizedOverlay{
私有静态int maxNum=5;
私有OverlayItem overlays[]=新OverlayItem[maxNum];
私有整数指数=0;
私有布尔满=假;
私人语境;
私有覆盖项先前覆盖;
公共MyOverlays(上下文、可绘制的defaultMarker){
super(boundCenterBottom(defaultMarker));
this.context=上下文;
}
@凌驾
受保护的OverlayItem createItem(int i){
返回覆盖层[i];
}
@凌驾
公共整数大小(){
如果(完整){
返回覆盖层长度;
}否则{
收益指数;