android api with google map displays grid - android

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

Your problem is related with the emulator, you need to install to APK's.
I had similar problems so I prepared step by step tutorial to show how you can use google map android v2 on emulator(android 4.2.2) have a look at to my blog: http://umut.tekguc.info/en/content/google-android-map-v2-step-step

You need to generate MD5 fingerprint from java keytool instead of SHA1.
Check this post to generate MD5 fingerprint:
How can I get the MD5 fingerprint from Java's keytool, not only SHA-1?

Related

Empty MapView in RecyclerView

I try to build a Chat Application in wich it should be possible for the user to send his location. I can pick the location via a PlcaPicker, this is all working fine. But when I try to display the Location in my MapView, it is empty without any Google Logo or Google Maps Symbol.
My Code for displaying the Location:
viewholder.mymap.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap googleMap) {
LatLng coordinates = new LatLng(43.535027499999984, 11.17666015625001);
MapsInitializer.initialize(Chat_Room.this);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions().position(coordinates));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates,13));
viewholder.mymap.onResume();
}
});
And my MapView:
<com.google.android.gms.maps.MapView
android:id="#+id/mymap"
android:layout_width="250dp"
android:layout_height="200dp"
android:layout_alignParentEnd="true"/>
I read that I can also use a Fragment but I dont know how to implement it and why my code is not working.
EDIT
My Manifest
<manifest>
<application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key" />
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
UPDATE
When I use a Fragment like this:
<fragment
android:id="#+id/mymap"
android:layout_width="250dp"
android:layout_height="200dp"
android:layout_alignParentEnd="true"
map:cameraZoom="13"
map:mapType="normal"
class="com.google.android.gms.maps.SupportMapFragment"
map:liteMode="true"/>
It shows the Google Logo on the left bottom corner, but I think my problem now is that my Adapter for my Recyclerview can't find the MapFragment, so it does not show anything. How can I find the MapFragment in my RecyclerAdapter?

Android google map shows blank

I'm trying to implement google maps V2 but the maps is showing blank. I've edited the manifest, created xml layout and the activity but maps is showing blank.
Here is what i did to the manifest:
<permission
android:name="com.biznismap.com.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.biznismap.com.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
and added this in as the first child of application node in the manifest:
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my_key" />
Here is my map xml layout:
<?xml version="1.0" encoding="utf-8"?>
<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:apiKey="my_key"
android:clickable="true" />
Here is my MapActivity:
public class ListingMap extends MapActivity {
private HelloItemizedOverlay itemizedoverlay;
private List<Overlay> mapOverlays;
private String lat, lng;
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listing_map);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.ic_launcher);
itemizedoverlay = new HelloItemizedOverlay(drawable);
getExtras();
}
private void getExtras() {
Bundle extras = getIntent().getExtras();
lat = extras.getString("lat");
lng = extras.getString("lng");
Log.v("--", lat+" "+lng);
float latitude=Float.valueOf(lat);
float longitude=Float.valueOf(lng);
GeoPoint point = new GeoPoint((int)(latitude * 1E6),(int)(longitude * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!",
"I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
}
So everything is going OK but, when I want to display something, the map is blank, and I get this from the emulator:
06-02 17:09:26.921: E/MapActivity(1772): Couldn't get connection factory client
So where am I going wrong, and how can I fix this problem?
You have two problems here. In v2 you may not use
<uses-library android:name="com.google.android.maps" />
, and your layout is invalid. If you want full-layout map, just use this:
<FrameLayout
... >
<fragment
...
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
On your Java code, use FragmentActivity and:
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.your_id)).getMap();
This way, you will get compatibity with pre-honeycomb devices. Good luck!
Here is what https://developers.google.com/maps/documentation/android/v1/hello-mapview says:
Note: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012. This means that from March 18th, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.
Your code is miximg v1 and v2 properties.
Either you don't have internet connectivity (my guess), or the key you entered in incorrect. Double check both these things.
Also, ensure the emulator you are using to test (if applicable) has the Google APIs installed.
MapView is no more used with API v2. Instead use :
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Accordingly, use FragmentActivity instead of MapActivity and inflate the map.
You can check Loading Map using Google Map API V2 for more details

ClassCastException when trying to get Google Play Services Map v2 to display

I've been beating me head against a wall with this for a few days now. I've read just about every post I can on the topic and nothing seems to get me across the finish line.
Trying to build an app using the Google Play Services Map v2 API.
I've got the API key, no problem.
Here are my bits: MainActivity.java
public class MainActivity extends FragmentActivity
{
GoogleMap googleMap;
#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);
googleMap = supportMapFragment.getMap();
}
else
{
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
}
#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;
}
}
activity_main.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Relevant manifest:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<permission
android:name="com.mcdaniel.mmm4.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mcdaniel.mmm4.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.persmission.INTERNET" />
<uses-permission android:name="android.persmission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.persmission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY API KEY" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
I've got past the NoClassDefFound error involving R$styleable, and ClassNotFound of the maps class, but I cannot get past this one.
Regarding the class, I've tried a couple different implementations without luck. This one seems the most explicit. No compile warnings.
My target is android-17 with min of android-11. I've got the library imported (with copy files option), and referenced by my project, and exported too.
Obviously there's something I'm missing. Please help!
Thanks,
David
this may helps you in xml change Like SupportMapFragment
<fragment
android:id="#+id/chk_aerrow_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_margin="5dp"
android:layout_height="100dp" />
for Details see Here
You can't cast a MapFragment (from your XML) to a SupportMapFragment.
One possible solution is to change the MapFragment in your XML to a SupportMapFragment as ankitmakwana suggests in his answer.
A better approach would in my opinion be to set minimal supported API to API12 instead of API11 and use a MapFragment instead of a SupportMapFragment. Then you don't have to worry about a compatability library.
Setting minimal supported API to API12 instead of API11 shouldn't render (almost) any devices uncompatible with your app, as according to this answer posted by one of the biggest Android gurus here in SO, there are basically no devices running API11.
If you chose to go this way, just keep your XML as it is and change the following lines in your code from this:
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = supportMapFragment.getMap();
to this:
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
It will work then.
My target is android-17 with min of android-11
Your min sdk is 11.
Note : If you wish to run the app on api 11 and lower You will need to add support library as well.
http://developer.android.com/tools/extras/support-library.html
Use this
android:name="com.google.android.gms.maps.SupportMapFragment"
Since you din't add support library you got classcastexception
Also make sure you have followed all the steps from the below link
https://developers.google.com/maps/documentation/android/start
Edit
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment
MapFragment for api 12 and higher support fragment for api 11 and lowever

Getting started with osmdroid, mapview shows only grid

I am planning to use OSM in my android app and i decided to give osmdroid a try. Here is what i have done till now.
1: I downloaded the slf4j-android-1.5.8.jar and osmdroid-android-3.0.8.jar and copied them to my libs folder and added them to build path.
2: My Xml layout file code looks like this.
<org.osmdroid.views.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
3: I have added all the permissions to the manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
4: My on create method looks like this
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mapify);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
mapController = mapView.getController();
mapController.setZoom(15);
}
My problem is that despite the code running fine i am not able to see the map when i run on my emulator. I am connected to internet and am able to see maps while using google map view.
I have look around the internet and also some questions in stackoverflow regarding same issue. Most of them either seem to have forgotten to add permissions or to add slf4j to build path. I have done both so i am at loss at what have i done wrong. Would be very grateful if you provided some insight.
Solved:
I don't know what is the reason but the map displays after i relaunch it a few times. After that everything seems to work fine. This happens again when i try in new virtual device. When i close and relaunch the app few times it starts working fine.
This is an old question, but in case somebody needs the answer. This may be caused if the emulator does not have an external storage to cache map tiles. I created an emulator with SD card and that solved the problem
open street maps (osmdroid) shows grey tiles not map in PC

osmdroid displays an empty grid

I wanted to try out having OpenStreetMap integration by osmdroid, but I got stuck at an issue where I have no idea what is missing. The scenario is as follows:
Symptom: Map widget gets displayed but only with an empty grid.
This is in my Activity class:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapView mapView = new MapView(this, 256);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
setContentView(mapView);
}
(I tried selecting various TileSources with seemingly no difference)
My Manifest also includes these permissions (as a child of <manifest>, after <uses-sdk>):
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...and my emulator is otherwise connected to the internet, eg. web browsers work.
osmdroid and slf4j are in the build path. The app compiles without a problem and generates no exceptions.
What could be wrong?
Many thanks!
SOLVED: This was caused by my emulator not having an external storage to cache map tiles.
I'm pretty new to OSMdroid too but try doing this?
setContentView(R.layout.offline_map_activity);
mapView = (MapView) findViewById(R.id.openmapview);
You would also need to have offline_map_activity.xml in your res/layouts:
<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:orientation="vertical" >
<org.osmdroid.views.MapView
android:id="#+id/openmapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Hope this works for you. At least this worked for my codes :)
i tink your Device has don't SD. You have change the Cache Path
OpenStreetMapTileProviderConstants.setCachePath(this.getFilesDir().getAbsolutePath());

Categories

Resources