can't display Openstreetmap - android

I want to display a part of a OSM but i don't know what's the problem with my code, when I run it, the map didn't display:
No error appear but the map didn't only display! I work with eclipse and the emulator Google API 8!
here is my MainActivity code:
package com.formation.dsmap1;
import org.mapsforge.android.maps.MapActivity;
import org.mapsforge.android.maps.MapView;
import android.annotation.SuppressLint;
//import android.annotation.SuppressLint;
//import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
//import android.os.Environment;
public class MainActivity extends MapActivity {
// #SuppressLint("SdCardPath")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapView mapView = new MapView(this);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setEnabled(true);
// mapView.setMapFile("/sdcard/essai.jpg");
// setContentView(mapView);
mapView.setMapFile(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "essai.osm");
setContentView(mapView);
}
}
and my AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.formation.dsmap1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.formation.dsmap1.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>
</application>
</manifest>
Can you help me please?

add this permission to your manifest and will be fine :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Related

Can't get map with Google Map API V2

I'm trying to get a simple map on my app by using Google Map API V2; I followed all the steps to do it but when I launch my app, I only get white page with a Google logo in the left bottom.
If someone can help me with this, it will be great..
This is the XML file:
<fragment 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:id="#+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
This is the file Java:
package com.example.ismail.location_test;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
And finally the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<uses-permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE"/>
<permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<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" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBbHBnsC_YhHKQhhsnaahYiT3GltK52It0" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I don't see anything wrong with your code. The symptom you decribe point to a not valid api key or gps is turned off, or even your are running this is an emulator with no google play installed. Check what google play versions is installed and used under build.gradle. eg:
dependencies {
compile 'com.google.android.gms:play-services:6.5.87'
I suggest you post your debuger log, if it is an api error it will state it there.
I suspect 3 things wrong in your code :
(1) Declare permission before using it :
<permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<!-- after declare use this -->
<uses-permission android:name="com.example.ismail.location_test.permission.MAPS_RECEIVE"/>
(2) Missing Declare gms version variable :
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
(3) Missing declare API_KEY :
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaS33yBBDxSDFsdf33BK-7HCasdfSADFfa72wJnKLZvq6A" />
Please check with above 3 suspects first : then if still error is there you can re-confirm steps to enable Google Maps from here

Android and google maps api v2 manifest error

I'm trying to run simple app with maps, here is my manifest.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpsWakeUpper"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="19"/>
<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="android.permission.access_coarse_location"/>
<uses-permission android:name="android.permission.access_fine_location"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxx"/>
</activity>
</application>
</manifest>
and my main activity
package com.example.gpsWakeUpper;
import android.app.Activity;
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.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MyActivity extends FragmentActivity {
static final LatLng WROCLAW = new LatLng(51.06, 17.01);
private GoogleMap map;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if(map!=null)
{
Marker wroclaw = map.addMarker(new MarkerOptions().position(WROCLAW).title("Wroclaw"));
map.moveCamera((CameraUpdateFactory.newLatLngZoom(WROCLAW, 15)));
}
}
}
For me it looks like everything is ok but i recive error
Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
So i' wondering whats wrong with my androidmanifest file, any ideas or clues?
You need to put both Maps related <meta-data> elements as direct "child" of <application> - you placed it as part of <activity> which is too deep and wrong. It should be like that:
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxx"/>
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Add below lines in Manifest.xml
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBzJyhrJbxLDYoBVnWP8P2xrXXXXXXXXXX"/>
...........................
//your activities here
</application >

Android: Testing app on Google Maps

I have a tablet Genesis GT-7240, Android 4.1.1, Kernel 3.0.36+.
My manifest.xml:
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17" />
It is a simple app, using Google Maps and so it must be compiled with API GOOGLE.
As I testing in a real device, I checked 'Unknown sources', copied the compiled apk into 'download' folder of the tablet, and I tried install it as I always usually do.
However, has a message
X App not instaled.
Another tablet, which has Android 3.2, the same app works perfectly.
Is there a issue with Android 4.1 and Api Google compilation?
[Editing]
My manifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MY_PACKAGE_HERE"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<permission android:name="MY_PACKAGE_HERE.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="MY_PACKAGE_HERE.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="MY_PACKAGE_HERE.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>
<uses-library android:required="true" android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_APY_KEY_HERE"/>
</application>
</manifest>
My activity_main layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
My MainActivity.java:
package MY_PACKAGE_HERE;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.*;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
private GoogleMap gm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if (status == ConnectionResult.SUCCESS) {
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
gm = supportMapFragment.getMap();
}
else {
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
}//onCreate
//*****************************
#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;
}
}

GoogleMapsDemo gives IllegalStateException

I have did all steps which is give at google but lastly it give's this
errorCaused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapsdemo"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.googlemapsdemo.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="AIzaSyBLHwjdXsQK0sszxfrkoncHlqU3d2mDJok" />
</application>
</manifest>
MainActivity.java:
package com.example.googlemapsdemo;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity
{
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try
{
// Loading map
initilizeMap();
} catch (Exception e)
{
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap()
{
if (googleMap == null)
{
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null)
{
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume()
{
super.onResume();
initilizeMap();
}
}
manifest file
For eclipse add this :
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
If you are using Android Studio(latest version) with gradle0.7+ then add this line:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your Key" />
Add the Google Play services version to your app's manifest
Edit your application's AndroidManifest.xml file, and add the
following declaration within the element. This embeds the version of
Google Play services that the app was compiled with.
You just need to add <meta-data> under <application> tag into your AndroidManifest.xml
....<application>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>

Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException: util.kalyan.HelloGoogleMapsActivity

I have included all the necessary fields correctly.
But still, I am not able to launch the Google map on my emulator.
Checked the internet permissions also.
Getting error like:
E/AndroidRuntime(2064): java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{util.kalyan/util.kalyan.HelloGoogleMapsActivity}:
java.lang.ClassNotFoundException: util.kalyan.HelloGoogleMapsActivity
Please find below my code.
HelloGoogleMapsActivity.java
package util.kalyan;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import util.kalyan.R;
public class HelloGoogleMapsActivity extends MapActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="util.kalyan"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-library android:name="com.google.android.maps"></uses-library>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" >
<activity android:name=".HelloGoogleMapsActivity" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses- permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Any one please help me in this at the earliest.
Thanks in advance.
Change the android:name in activity definition
from
<activity android:name=".HelloGoogleMapsActivity" ../>
to
<activity android:name="util.kalyan.HelloGoogleMapsActivity" ../>
You emulator target should be one that includes Google APIs (Google Inc.).
Right click on your HelloGoogleMapsActivity class > BuildPath > Exclude Then Right click on your HelloGoogleMapsActivity class > BuildPath > Include your class again

Categories

Resources