谷歌地图android api显示网格 [英] android api with google map displays grid
问题描述
我正在创建一个使用google maps api v2的android应用程序。
我相信我已经做了所有的谷歌教程赛斯,但我仍然只得到谷歌地图网格(没有地图)。我已经使用keystore.debug的SHA1创建了一个调试密钥。
Eclipse java编译器版本1.7
项目java编译器版本1.6
应用清单:
< manifest ... >
< uses-sdk
android:minSdkVersion =8
android:targetSdkVersion =8/>
<使用权限android:name =android.permission.INTERNET/>
<使用权限android:name =android.permission.ACCESS_WIFI_STATE/>
< uses-permission android:name =android.permission.CHANGE_WIFI_STATE/>
< uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/>
< uses-permission android:name =android.permission.ACCESS_COARSE_LOCATION/>
< uses-permission android:name =my.app.test.permission.MAPS_RECEIVE/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
< uses-feature
android:glEsVersion =0x00020000
android:required =true/>
< application>
<活动>
...
< / activity>
< meta-data
android:name =com.google.android.maps.v2.API_KEY
android:value =xxxxxxxxxxxxxxxxxxxxxxxxxxx/>
< uses-library android:name =com.google.android.maps/>
< / application>
< / manifest>
Map xml:
< 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:background =@ color / BackGroundColor
android:orientation =vertical
tools:context =。test>
< LinearLayout
android:layout_width =fill_parent
android:layout_height =wrap_content
android:orientation =vertical
android: paddingRight =10dp
android:paddingTop =5dp>
< 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 = xxxxxxxxxxxxxxxxxxxxxxxxxx>
< /com.google.android.maps.MapView>
< / LinearLayout>
< / LinearLayout>
地图活动:
public class Map扩展MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_map);
mapView =(MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mc = mapView.getController();
字符串坐标[] = {1.352566007,103.78921587};
double lat = Double.parseDouble(coordinates [0]);
double lng = Double.parseDouble(coordinates [1]);
p =新的GeoPoint(
(int)(lat * 1E6),
(int)(lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed(){return false; }
}
我知道那里大量的帖子都有同样的问题。我已阅读他们所有!
我已经多次创建密钥,但仍然是一样的...
任何想法是什么错误,我只看到网格?该应用程序与AVD以及Android 2.2.1版本的三星手机具有相同的结果。
应用API V2,那么你使用的是错误的对象,你需要修复的东西很少:
1。删除:
< uses-library android:name =com.google.android.maps/>
这是Google Map API V1的许可。
< permission android:name =your.application.package.permission.MAPS_RECEIVEandroid:protectionLevel =signature/>
< uses-permission android:name =your.application.package.permission.MAPS_RECEIVE/>
更改: your.application.package
至您当前的应用程序包。
3。在您定位 4.您的 5。您可以获取更多信息,了解如何在博客文章中进行这些更改写了关于如何将Google Map API V2添加到您的项目中的文章: I am creating an android application that uses google maps api v2.
I believe I have done everything as google tutorial sais but still I am getting only the google maps grid (no map). I have created a debug key from using SHA1 of keystore.debug. below are my settings:
Eclipse java compiler version 1.7
Project java compiler version 1.6 application manifest: Map xml: Map Activity: } I know that there are plenty of post with the same problem. I have read them all!!!
I have created the key several times but still the same...
Any ideas what is wrong and I am only seeing the grid? the application has the same outcome to AVD as well as to a Samsung mobile with android version 2.2.1 If you writing you application for API V2 then you are using the wrong objects, few things you need to fix: 1. Remove this: it's a permission for Google Map API V1. 2. you have to add this 2 permissions: change: 3. As you targeting 4. Your 5. You can can get more information on how to make those changes in a blog post I wrote on how to add Google Map API V2 to your project: 这篇关于谷歌地图android api显示网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! SDK v8
为了使用Google Map API V2中的 SupportMapFragment
,向您的应用程序添加片段支持,因此您需要添加 google-support-v4
并将地图对象更改为
SupportMapFragment
。 $ b MapActivity
必须更改为 FragmentActivity
。
<manifest ...>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="my.app.test.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application>
<activity>
...
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxx"/>
<uses-library android:name="com.google.android.maps"/>
</application>
</manifest>
<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:background="@color/BackGroundColor"
android:orientation="vertical"
tools:context=".test" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<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="xxxxxxxxxxxxxxxxxxxxxxxxxx" >
</com.google.android.maps.MapView>
</LinearLayout>
</LinearLayout>
public class Map extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mc = mapView.getController();
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() { return false; }
<uses-library android:name="com.google.android.maps"/>
<permission android:name="your.application.package.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/>
your.application.package
to your current application package.SDK v8
, you have to add fragment support to your application in order to use the SupportMapFragment
from Google Map API V2, So you need to add google-support-v4
and change your map object to SupportMapFragment
. MapActivity
has to be changed to FragmentActivity
.