google map not working on both emulator and device

时间秒杀一切 提交于 2019-11-29 12:46:56

In your manifest file you have to add:

<permission
  android:name="your.application.package.permission.MAPS_RECEIVE"
  android:protectionLevel="signature" />

Like from: your.application.package to: com.themontcalm.droid

And yes if you are using

<uses-library android:name="com.google.android.maps" />

then remove from manifest file:

and add your api code to in manifest file also:

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Your_Map_Key" />

And in manifest file you are missing this:

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

so also add to this also in manifest file:

you should change android.R.id.content with R.id.map in your code

Something like:

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

In order to use google Map Service,

Please visit code.google.com and get you ApiKey.

create a project there->go to services->Activate the Google Maps Android API v2. Then Create Key for your application.

Add the following permissions to your manifest.

 <uses-permission android:name="com.anchit.locationapi.maps.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" />

use

 <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="your_apikey" />

also add

<permission
        android:name="com.anchit.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

inside your Application Tag in manifest.

Use

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
        .getMap();

in your code.

and set the other required properties. Now Run the Application.

In your Manifest add

<permission
  android:name="your.application.package.permission.MAPS_RECEIVE"
  android:protectionLevel="signature" />

Also add to your application tag

<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="Your_Map_Key" />

You can also visit Google Map V2 , this and Example of map v2

Hope it helps you.

Edit:

As per you said Add this xml file in your project

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

And access it with in your map activity

 map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
        .getMap(); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!