Android地图不显示。只有网格 [英] Android Map NOT showing. Only Grids
问题描述
解决问题
解决方案摘要:确保您不是api v1的类。现在,当我工作时,模拟器无法测试应用程序。因此请在实际设备上进行测试。
最后,如果应用程序正确运行但不显示地图,那么您的密钥有问题。
我在这里注意到catlog并没有说那个键是错的,应用程序运行了,但是没有显示map。
m试图2天来制作一个简单的Google地图android应用程序,它只是在Activity上显示地图,但失败了。尝试每个教程到谷歌的第二页。什么都没有有点有用只是我在书中遵循的应用程序但它显示网格和没有MAP。通常人们会给出关键错误的答案,但事实并非如此。我的钥匙是对的,我准确地在生成钥匙上工作。
我正在使用Google Maps Android API v2密钥。
这是我的activity_main.xml
<?xml版本=1.0encoding =utf-8?>
< LinearLayout xmlns:android =http://schemas.android.com/apk/res/android
android:layout_width =fill_parent
android:layout_height =fill_parent
android:orientation =vertical>
< com.google.android.maps.MapView
android:id =@ + id / mapView
android:layout_width =fill_parent
android :layout_height =fill_parent
android:apiKey =0AeGR0UwGH4pYmhcwaA9JF5mMEtrmwFe8RobTHA
android:clickable =true
android:enabled =true/>
< / LinearLayout>
这是我的MainActivity.java
package com.example.lbs;
导入android.os.Bundle;
导入android.view.Menu;
import com.google.android.maps.MapActivity;
public class MainActivity extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(菜单菜单){
//膨胀菜单;这会将项目添加到操作栏(如果存在)。
getMenuInflater()。inflate(R.menu.main,menu);
返回true;
$ b $覆盖
保护布尔isRouteDisplayed(){
// TODO自动生成的方法存根
返回false;
}
}
这是我的AndroidManifest.xml
<?xml version =1.0encoding =utf-8?>
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.example.lbs
android:versionCode = 1
android:versionName =1.0>
< uses-sdk
android:minSdkVersion =8
android:targetSdkVersion =17/>
< uses-feature
android:glEsVersion =0x00020000
android:required =true/>
<使用权限android:name =android.permission.INTERNET/>
< permission
android:name =com.example.lbs.permission.MAPS_RECEIVE
android:protectionLevel =signature/>
<使用权限android:name =com.example.lbs.permission.MAPS_RECEIVE/>
< uses-permission android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
< uses-permission android:name =android.permission.ACCESS_COARSE_LOCATION/>
< 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.lbs.MainActivity
android:label =@ string / app_name>
< intent-filter>
并且我以这个结尾
更新2:
现在我试着使其在实际的Android设备上工作。这是Android 2.3。
所以做更多的工作。我结束了我的活动
以及我可以在我的CatLog中看到的是
所以地图不会显示...请帮助.. 。
更新3:
问题出在API密钥中。我在logcat中看不到关于错误键的任何内容。应用程序运行但不显示地图。所以我重新获得了关键。
和这里我们去
您的问题是您为Google Maps API V2生成密钥,但您尝试使用Google Maps API V1对象 MapView
code>:
< com.google.android.maps.MapView
android:id = @ + id / mapView
android:layout_width =fill_parent
android:layout_height =fill_parent
android:apiKey =0AeGR0UwGH4pYmhcwaA9JF5mMEtrmwFe8RobTHA
android:clickable =true
android:enabled =true/>
您应该使用 MapFramgent
或 SupportMapFragment
,具体取决于您定位的API级别,您可以在本指南中撰写的关于如何将Google Maps API V2集成到应用程序中的完整说明:
更新:
第二个屏幕截图是您想要的模拟器。 Google Play服务
没有安装在模拟器上,并且您看到了所见的原因。尝试在安装了 Google Play服务
的设备上测试此应用,并且该应用可以正常工作。
PROBLEM IS SOLVED
Short Summary of solution: Make sure you are not classes of api v1. Right now when I was working, the emulator was useless to test the application. So test it on actual device.
Finally if application run correctly but don't show the map then you have problem with key.
What I noticed here is the catlog don't say that key is wrong, application run, but map is not shown.
I'm trying for 2 days to make a single simple Google map android application that just show map on Activity but failed. Tried every tutorial upto google's second page. Nothing works. What works a bit is only the application that I'm following in book But it shows grid and no MAP. Usually people gives answer of that the key is wrong but it is not. My key is right I worked accurately in generating key.
I'm using Google Maps Android API v2 key.
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0AeGR0UwGH4pYmhcwaA9JF5mMEtrmwFe8RobTHA"
android:clickable="true"
android:enabled="true" />
</LinearLayout>
Here is my MainActivity.java
package com.example.lbs;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.maps.MapActivity;
public class MainActivity extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lbs"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name="com.example.lbs.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.lbs.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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="android.permission.ACCESS_COARSE_LOCATION" />
<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.lbs.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB1RpoULFVTRkXREZX0ZAwxcz4_75Y0HYc" />
</manifest>
On catlog, when application is running I'm getting this
IOException processing: 26
java.io.IOException: Server returned: 3
at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
Update 1:
After all above, As i read at some places the code may only be for API key v1. So I followed a tutorial completely from start at https://blog-emildesign.rhcloud.com/?p=435
and I ended up with this
UPDATE 2:
Now I tried to make it work on actual Android device. It's android 2.3.
So doing a bit more work. I end up with in my activity
and what I can see at my CatLog is
So the map is not still showing... Please help...
Update 3:
The problem was in API key. I could not see anything in logcat about the wrong key. application runs but don't show the map. So I regenerated the key.
AND HERE WE GO
解决方案 Your problem is that you produce the key for Google Maps API V2 but you are trying to use Google Maps API V1 object MapView
:
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0AeGR0UwGH4pYmhcwaA9JF5mMEtrmwFe8RobTHA"
android:clickable="true"
android:enabled="true" />
Instead you should use MapFramgent
or SupportMapFragment
, depending on what API level you are targeting, you can get a full explanation on how to integrate Google Maps API V2 in your application in this guide I wrote on this matter:
UPDATE:
The second screen shot is what you suppose to get on the emulator. Google Play Services
are not installed on the emulator and that the reason you see what you see. try to test this app on a device with Google Play Services
installed and it should work.
这篇关于Android地图不显示。只有网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!