android - Android 中未显示谷歌地图

标签 android google-maps

我在我的示例 android 项目中使用谷歌地图,但它只显示标题,没有其他任何 map 被显示,我已经遵循了 lynda 教程, map 键也是使用谷歌地图模拟器生成的,并在真实的欺骗上进行了测试,它们仍然存在不工作。这是下面的代码。请帮忙

布局文件

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <com.google.android.maps.MapView
        android:id="@+id/map"
        android:clickable="true"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="MyMApKey" />

</RelativeLayout>

map Activity :

package com.example.maptest;

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.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;

public class MainActivity extends MapActivity {
      LocationListener listener ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapView view = (MapView) findViewById(R.id.map);
        view.setBuiltInZoomControls(true);
        final MapController control = view.getController();
        final LocationManager manager = (LocationManager) this
                .getSystemService(Context.LOCATION_SERVICE);
          listener = new LocationListener() {

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

            }

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

            }

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

            }

            @Override
            public void onLocationChanged(Location location) {
                // TODO Auto-generated method stub

                control.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));
                manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0,listener);

            }
        };

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

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

}

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.maptest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="14" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="com.example.maptest.MainActivity"
            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>

这是输出 enter image description here

最佳答案

注意:Google Maps Android API 版本 1 已于 2012 年 12 月 3 日正式弃用。这意味着从 2013 年 3 月 18 日起,您将无法再为该版本请求 API key 。不会向 Google Maps Android API v1 添加任何新功能。但是,使用 v1 的应用程序将继续在设备上运行。鼓励现有和新的开发人员使用

转到此链接 google map api v2 给出了逐步描述。 https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key

关于android - Android 中未显示谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863075/

相关文章:

android - 在 Eclipse 上安装 ADT

javascript - 基于数据库的谷歌地图自定义标记

android - Mapbox Android SDK : Bring marker to front

android - TransactionTooLargeException 怎么办

javascript - 如何访问 Google Maps JavaScript API v3 中的默认 KmlLayer

java - Google map Java 客户端 - GeocodingApi.reverseGeocode 不返回结果

javascript - 如何在没有任何鼠标事件的情况下默认显示标记内容?

javascript - 将地点 ID 位置传递到 Google map API 中的目的地

android - 从sqlite数据库中获取总数

android - 如何在浏览器 Android 中点击 url 启动应用程序