Java 地图正在加载,但可以';我看不到Android开发的地图

Java 地图正在加载,但可以';我看不到Android开发的地图,java,android,google-maps,Java,Android,Google Maps,我正在学习Android开发与林达视频教程 我正在使用GoogleMapAPIv2来显示地图。我已经按照教程完成了所有步骤 当我尝试在我的设备中查看应用程序时,我可以看到Google徽标,但地图不可见。(我看到底部有谷歌标志的白色背景) 我已经添加了我的代码和屏幕截图。有人能帮我修一下吗。谢谢 截图 我的java代码 package lk.adspace.jaffnatemples; import java.io.IOException; import java.util.List; im

我正在学习Android开发与林达视频教程

我正在使用GoogleMapAPIv2来显示地图。我已经按照教程完成了所有步骤

当我尝试在我的设备中查看应用程序时,我可以看到Google徽标,但地图不可见。(我看到底部有谷歌标志的白色背景)

我已经添加了我的代码和屏幕截图。有人能帮我修一下吗。谢谢

截图

我的java代码

package lk.adspace.jaffnatemples;

import java.io.IOException;
import java.util.List;

import android.app.Dialog;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

public class MainActivity extends FragmentActivity {

private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;

@SuppressWarnings("unused")
private static final double SEATTLE_LAT = 47.60621,
SEATTLE_LNG =-122.33207, 
SYDNEY_LAT = -33.867487,
SYDNEY_LNG = 151.20699, 
NEWYORK_LAT = 40.714353, 
NEWYORK_LNG = -74.005973;
private static final float DEFAULTZOOM = 15;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (servicesOK()) {
        setContentView(R.layout.activity_map);

        if (initMap()) {
            Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();
            gotoLocation(SEATTLE_LAT, SEATTLE_LNG, DEFAULTZOOM);
        }
        else {
            Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show();
        }
    }
    else {
        setContentView(R.layout.activity_main);
    }

}

@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;
}

public boolean servicesOK() {
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {
        return true;
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();
    }
    else {
        Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
    }
    return false;
}

private boolean initMap() {
    if (mMap == null) {
        SupportMapFragment mapFrag =
                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mMap = mapFrag.getMap();
    }
    return (mMap != null);
}

private void gotoLocation(double lat, double lng,
        float zoom) {
    LatLng ll = new LatLng(lat, lng);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
    mMap.moveCamera(update);
}

public void geoLocate(View v) throws IOException {
    hideSoftKeyboard(v);

    EditText et = (EditText) findViewById(R.id.editText1);
    String location = et.getText().toString();

    Geocoder gc = new Geocoder(this);
    List<Address> list = gc.getFromLocationName(location, 1);
    Address add = list.get(0);
    String locality = add.getLocality();
    Toast.makeText(this, locality, Toast.LENGTH_LONG).show();

    double lat = add.getLatitude();
    double lng = add.getLongitude();

    gotoLocation(lat, lng, DEFAULTZOOM);

}

private void hideSoftKeyboard(View v) {
    InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

}
包lk.adspace.jaffnatemples;
导入java.io.IOException;
导入java.util.List;
导入android.app.Dialog;
导入android.location.Address;
导入android.location.Geocoder;
导入android.os.Bundle;
导入android.support.v4.app.FragmentActivity;
导入android.view.Menu;
导入android.view.view;
导入android.view.inputmethod.InputMethodManager;
导入android.widget.EditText;
导入android.widget.Toast;
导入com.google.android.gms.common.ConnectionResult;
导入com.google.android.gms.common.GooglePlayServicesUtil;
导入com.google.android.gms.maps.CameraUpdate;
导入com.google.android.gms.maps.CameraUpdateFactory;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.SupportMapFragment;
导入com.google.android.gms.maps.model.LatLng;
公共类MainActivity扩展了FragmentActivity{
私人静态最终内部GPS错误对话框请求=9001;
谷歌地图;
@抑制警告(“未使用”)
私人静态最终双人西雅图_LAT=47.60621,
西雅图液化天然气=-122.33207,
悉尼时间=-33.867487,
悉尼液化天然气=151.20699,
纽约拉特=40.714353,
纽约液化天然气=-74.005973;
私有静态最终浮点默认缩放=15;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(servicesOK()){
setContentView(R.layout.activity_map);
if(initMap()){
Toast.makeText(这是“准备映射!”,Toast.LENGTH_SHORT.show();
gotoLocation(西雅图拉特、西雅图液化天然气、德国);
}
否则{
Toast.makeText(此“地图不可用!”,Toast.LENGTH_SHORT.show();
}
}
否则{
setContentView(R.layout.activity_main);
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
公共布尔服务sok(){
int isAvailable=GooglePlayServicesUtil.isGooglePlayServicesAvailable(此);
if(isAvailable==ConnectionResult.SUCCESS){
返回true;
}
else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable)){
Dialog Dialog=GooglePlayServicesUtil.getErrorDialog(此为GPS\u ERRORDIALOG\u请求可用);
dialog.show();
}
否则{
Toast.makeText(这是“无法连接到Google Play服务”,Toast.LENGTH_SHORT.show();
}
返回false;
}
私有布尔initMap(){
如果(mMap==null){
SupportMapFragment mapFrag=
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mMap=mapFrag.getMap();
}
返回值(mMap!=null);
}
私人空位(双lat、双lng、,
浮动(缩放){
LatLng ll=新LatLng(lat,lng);
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(ll,缩放);
移动摄像头(更新);
}
公共void地理定位(视图v)引发IOException{
隐藏键盘(v);
EditText et=(EditText)findViewById(R.id.editText1);
字符串位置=et.getText().toString();
地理编码器gc=新地理编码器(本);
List List=gc.getFromLocationName(位置,1);
地址add=list.get(0);
String locality=add.getLocality();
Toast.makeText(this,locality,Toast.LENGTH_LONG).show();
double lat=add.getLatitude();
double lng=add.getLongitude();
gotoLocation(拉丁美洲、液化天然气、天然气);
}
专用无效隐藏键盘(视图v){
InputMethodManager imm=(InputMethodManager)getSystemService(输入方法服务);
imm.hideSoftInputFromWindow(v.getWindowToken(),0);
}
}
我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:text="Location:"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|center_vertical"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:text="Go" 
        android:onClick="geoLocate"/>
</LinearLayout>

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="292dp"
    android:layout_height="374dp" />

</LinearLayout>

我的清单文件

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

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

        <permission 
            android:name="lk.adspace.jaffnatemples.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>

        <uses-permission android:name="lk.adspace.jaffnatemples.permission.MAPS_RECEIVE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission 
            android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

        <uses-feature 
            android:glEsVersion="0x00020000"
            android:required="true"/>

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="lk.adspace.jaffnatemples.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>


                   <meta-data android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" />


            <meta-data 
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="I Added my Api Key"/>

        </application>

    </manifest>


有人能帮我修一下吗。谢谢。

您只能通过手机查看。
您现在看到的是您在Emulator中所能获得的所有信息。

您没有要求任何gps权限

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

此外,由于您使用的是假位置,您可能也希望包括此位置。我不知道这是否与本案有关,但以防万一

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


另外,我知道你说你目前正在一台设备上进行测试,但是对于那些对在模拟器上运行谷歌地图(使用新的谷歌游戏依赖项)感兴趣的人来说,这是可以做到的

您是使用调试密钥库生成API密钥,还是使用另一个密钥库为应用程序签名以为设备生成密钥库?API密钥绑定到密钥库,如果您使用另一个开发人员计算机上的另一个密钥库或另一个调试密钥库进行签名,则必须更改此API密钥。

更新的清单使用此

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

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

    <permission
        android:name="lk.adspace.jaffnatemples.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <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" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="com.ram.googlemapsv2.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="lk.adspace.jaffnatemples.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>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="v3" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="your api key" />
    </application>

</manifest>

似乎写权限的人是对的, 但我也遇到了同样的问题,解决方法是在
谷歌的互联网站点,你可以在那里获得api密钥。 因为我在同一天用几乎相同的软件包名构建了另一个项目, 忘了我在那个项目中生成了api密钥,它在seco中对我不起作用