问题描述
我正在创建一个使用google maps api v2的android应用程序。
我相信我已经做了所有的谷歌教程赛斯,但我仍然只得到谷歌地图网格(没有地图)。我已经使用keystore.debug的SHA1创建了一个调试密钥。
Eclipse java编译器版本1.7
项目java编译器版本1.6
应用清单:
$ b4.您的 MapActivity 必须更改为 FragmentActivity 。
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:
<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>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>Map Activity:
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; }}
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:
<uses-library android:name="com.google.android.maps"/>it's a permission for Google Map API V1.
2. you have to add this 2 permissions:
<permission android:name="your.application.package.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/>change: your.application.package to your current application package.
3. As you targeting 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.
4. Your MapActivity has to be changed to FragmentActivity.
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显示网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!