Unable to display map on Android

I want to display a map in an Android emulator. To do this, I installed Google Play services and imported them into workspaces and made them links in my project. But I am launching an application that shows Goolgle game services, and not on your phone. I can’t understand why this is visible. I am here full code.
Here is my manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.map" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="com.example.map.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" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.map.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyDcNgF68UPm1cNdlJmr41PGYG06z4P_NyI" /> </application> </manifest> main.xml <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" /> </RelativeLayout> .java file is here package com.example.map; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } ![enter image description here][1] @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 
Image of emulator Could you give me an answer why it shows. It really helps me.
+4
source share
3 answers

Point 1. Use the code below if you are developing an application for API level 8.

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

see MapFragment . Use this class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment.

Point 2. Extend the FragmentActivtiy class instead of Activity

Private GoogleMap googleMap;

  public void loadGoogleMap(){ if(googleMap==null){ // Getting Google Play availability status int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); // Showing status if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, (Activity)context, requestCode); dialog.show(); }else{ // Getting reference to the SupportMapFragment of activity_main.xml SupportMapFragment fm = (SupportMapFragment) this.YOUR_CLASS_NAME.getSupportFragmentManager() .findFragmentById(R.id.my_comm_nearme_map); // Getting GoogleMap object from the fragment googleMap = fm.getMap(); //setting map type googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); UiSettings uiSettings = googleMap.getUiSettings(); uiSettings.setCompassEnabled(false); uiSettings.setZoomControlsEnabled(true); uiSettings.setMyLocationButtonEnabled(false); } } } 

Point 3.

 But i run application it shows Goolgle play services in not in Your phone. 

Android for Google Play services to run maps. You can download it from the market and try again, Maps will work.

If you install an error installing Google Play services , your device is not compatible.

+3
source

enter image description here Please go to google api and google api google api android v2 only

Google API Console β†’ Service β†’ Google Maps Android API v2 β†’

than the new API key and test.

+1
source

use this code to run a customized google map below api-11 level, it also runs successfully in higher versions.

import the google-play-services_lib project into your workspace from \ sdk \ extras \ google \ google_play_services_froyo \ libproject.

right-click on the project-> properties-> android-> right-click the flag in the name of the library panel as "there is a library" and click "Apply" and click "OK".

now go to your projects property-android-> in the library panel-> click add-> now select "google-play-services_lib" in options-> apply> ok

Now use this code

  package com.hmkcode.android; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { GoogleMap map; map = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map)).getMap(); map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng( 19.233442, 72.980851), 16)); map.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory .fromResource(R.drawable.house_flag)) .anchor(0.0f, 1.0f) .position(new LatLng(19.233442, 72.980851)) .title("Hello world")); } catch (NullPointerException e) { } } } 

layout.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:name="com.google.android.gms.maps.SupportMapFragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> 

in manifest

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hmkcode.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <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" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.hmkcode.android.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="use your obtained key" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application> </manifest> 

Now you can see a map that you will see, a button that can be used to update services.

0
source

Source: https://habr.com/ru/post/1496138/


All Articles