谷歌地图android api显示网格 [英] android api with google map displays grid

查看:142
本文介绍了谷歌地图android api显示网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用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。在您定位 SDK v8 为了使用Google Map API V2中的 SupportMapFragment ,向您的应用程序添加片段支持,因此您需要添加 google-support-v4 并将地图对象更改为 SupportMapFragment $ b

4.您的 MapActivity 必须更改为 FragmentActivity



5。您可以获取更多信息,了解如何在博客文章中进行这些更改写了关于如何将Google Map API V2添加到您的项目中的文章:

Google Maps 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:

Google Maps API V2

这篇关于谷歌地图android api显示网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆