谷歌地图不显示任何内容

时间:2014-12-02 12:44:21

标签: android google-maps google-maps-api-2

我使用MapFragment来显示Google地图。 我想我已经在代码中完成了所有工作,但地图并没有显示任何内容enter image description here 我想这是API密钥问题。

这就是我得到它的方式:

使用此命令生成SHA1 Fingerprintkeytool -list -v -keystore /Users/[USERNAME]/[debug.keystore path] -alias androiddebugkey -storepass android -keypass android

在Google开发者控制台中创建了新项目,启用了Google Maps Api V2,在凭据中创建了新的Android密钥

这是我从谷歌开发者控制台获得的项目凭据: enter image description here

这是Manifest文件:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="erpus.distribution" android:installLocation="auto">
  <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />
  <application android:label="ERPus.Distribution"></application>
  <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyA14yRAzOpkXeHD86MzZbqglUlM8DxSS-I" />
  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />  
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <permission android:name="erpus.distribution.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <uses-permission android:name="erpus.distribution.permission.MAPS_RECEIVE" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
  <uses-permission android:name="android.permission.BROADCAST_WAP_PUSH" />
  <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <application android:theme="@android:style/Theme.Holo.Light" />
  <uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
  <uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
  <uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
</manifest>

任何建议?

修改 我在Xamarin上写作。如果有人需要,我的片段就在这里:

public class ContractorMapFragment : Fragment {
    View view;
    private static int layoutId;

    public override void OnActivityCreated(Bundle savedInstanceState) {
        base.OnActivityCreated(savedInstanceState);

        MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
        GoogleMap Map = mapFrag.Map;
        if (Map != null) {
            Map.MapType = GoogleMap.MapTypeNormal;
            Map.UiSettings.CompassEnabled = true;
            Map.MyLocationEnabled = true;
        }
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view != null) {
            ViewGroup parent = (ViewGroup)view.Parent;
            if (parent != null) {
                parent.RemoveView(view);
            }
        }

        try {
            if (layoutId == 0)
                layoutId = Resource.Layout.MapFragmentLayout;
            view = inflater.Inflate(layoutId, container, false);
        }
        catch (InflateException e) {

        }
        return view;
    }
}

观看:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    class="com.google.android.gms.maps.MapFragment" />

1 个答案:

答案 0 :(得分:2)

Xamarin正在使用不同的debug.keystore!

keytool -exportcert -alias androiddebugkey -keystore ~/.local/share/Xamarin/Mono\ for\ Android/debug.keystore | openssl sha1 -binary | openssl base64

这应该可以解决你的问题。