Android GPS map shows grid - android

After 30 hours of programming and failing at this, I realised I couldn't do what I wanted. So this is a last ditch effort to score a pass.
Trying to implement google api to show stuff on a map.
I've basically followed the Android tutorial entirely and it still refuses to work.
It just shows the grid on the MapView, my friend tested my api key so it should be fine.
The only permission I was supposed to use is
android.permission.INTERNET
I've seen the other thread, but I'm positive the key is fine and I think the permission is in the right place.
<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="key"
/>
</LinearLayout>
manifest
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="false">
<uses-library android:name="com.google.android.maps" />
<activity
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class Main extends MapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
seems I was premature, I built another key, exactly as I did last time. This time the key worked.
but now the problem is, when I click on zoom, it force closes teh application

dont use debug.keystore. Use new keystore. Right click on ur project>Android tools> Export signed application package. Create new keystore (Remember alias name and password).
Now use following command in command prompt:
cd "C:\Program Files\Java\jdk1.7.0_01\bin
keytool -v -list -alias <ur alias name> -keystore <ur keystore name>.keystore -storepass android -keypass android
It asks for password later it gives a MD5 fingerprint Use that md5 fingerprint to generate google api key. Replace the key.
Now Project Right Click>Android tools>Export Signed Application package>
Use existing keystore
select previous keystore and u get apk in release mode. check installing this apk.It should run properly.

I think problem with your MyItemizedOverlay class only.
You mentioned when i click on zoom means zoom controls or on your android marker ??
I tested my code as you did but only the change is my own ItemizedOverlay class. its working fine for both zoom controls and marker click.
The only thing i can help you is, if your app crashed when you click marker on map, then you have to pass the Context to ItemizedOverlay class
If not, send your code i will try to solve your problem.

Related

Google map not displaying some landmarks in android

I am new to android and working on an application which display Google map. So I followed the steps for loading google map in my application and it worked successfully but the map shown in my app is not displaying some of the landmarks, which are usually displayed in Google map app.
For more explanation, the map in my application is displaying college
library, main driveway, Children’s Park near my location but it is not
displaying the college name,or similarly it is displaying street
numbers and road names but not displaying any of the restaurants,bars
or any business landmarks.
The xml code:
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
The java code :
package com.example.mapprototype;
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;
public class MainActivity extends Activity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
Google play service and google map api key are added in manifest file.
<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_api_key"/>
Do I need to add something else to display all the landmarks like bars,restaurant,colleges etc. that are displayed in google map default application .
Such minor details are not included in the Google Maps API.
However you can fetch nearby places using the Places API and make your own markers on the map.
Further readings:
Google Places API documentation
Usage example by Tutsplus

google map showing blank in genymotion

I am using Google Nexus 4.2.2 - with Google API on Genymotion. The google maps fragment is coming up empty. I have registered with the API and providing the key in the manifest file. Thanks for your help.
Layout:
<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"
tools:context=".MapsTestActivity" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</RelativeLayout>
Activity:
package com.chaseit.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.chaseit.R;
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.BitmapDescriptorFactory;
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 MapsTestActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps_test);
// setupMap();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
setupMap();
super.onResume();
}
private void setupMap() {
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.maps_test, menu);
return true;
}
}
I got the example code from http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Inorder to use google maps v2 in our android application, one must use google-play-services library. This Library works only if context is passed to check whether services is available to that devices. Add this line in your oncreate
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
Comment me about the result
Check the output log, search on maps, and see if warnings notices come up. In my case, I found:
09:03:34.197 E/Google Maps Android API( 7012): Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.
03-22 09:03:34.198 E/Google Maps Android API( 7012): In the Google Developer Console (https://console.developers.google.com)
03-22 09:03:34.198 E/Google Maps Android API( 7012): Ensure that the "Google Maps Android API v2" is enabled.
03-22 09:03:34.198 E/Google Maps Android API( 7012): Ensure that the following Android Key exists:
Double check on the following:
That you gave the correct SHA1 fingerprint of your application in google developer console (For me, somehow this changed)
That you gave the correct package name
That you included they API key in the manifest file (Obvious, yes, I know)
That the proper permissions are also set in manifest
ACCESS_COARSE_LOCATION
ACCESS_FINE_LOCATION
ACCESS_LOCATION_EXTRA_COMMANDS
ACCESS_MOCK_LOCATION
If using an emulator, insure that Google Play Services (including Maps) is installed.
More detailed directions can be found here.
In my case , I did not find a solution,the map is blank when it is opened and navigating the map does nothing , but I had a PlaceAutocompleteFragment and when i use it to search for a place I move the map to that place and it works , the map is now shown and you can navigate it .
you don't have to use PlaceAutocompleteFragment you can just get around the problem by moving the camera to a place you want when the map loads and then navigate from there , this can be done by adding this to the onMapReady() function :
LatLng latLng = new LatLng(15.501501,32.4325101) ;// change to the value you want
float zoom = 15.0f;
mapfragment.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));

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

The google map looks empty inside the simulator

public class Map extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
MapView mapView = (MapView) findViewById(R.id.myMapView1);
mapView.getController().animateTo(srcGeoPoint);
mapView.getController().setZoom(15);
}
the map.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="#+id/myMapView1"
android:layout_width="fill_parent"
android:layout_x="0px"
android:enabled="true"
android:clickable="true"
android:apiKey="Obtained Key here" android:layout_y="105px" android:layout_height="fill_parent">
</com.google.android.maps.MapView>
</LinearLayout>
I check the log there's only one red mark, Failed to find provider info for com.google.settings. everything else seems to be fine. I am wondering why the map is empty looking?
The MapView is empty when your Maps API key is expired or not matching with your debug signature key.
Try to generate a new one.
Inside every MapActivity, the isRouteDisplayed() method is required,
so override this method:
#Override protected boolean isRouteDisplayed() {
return false; }
This method is required for some accounting from the Maps service to
see if you're currently displaying any route information. In this
case, you're not, so return false.
source: http://developer.android.com/resources/tutorials/views/hello-mapview.html
Additional the android:layout_x="0px looks a little bit dodgy to me. I think it's only used in AbsoluteLayouts so deleting it should not harm.
Please check logs whether you are not getting "unable to authenticate error from google server". If yes there is issue with map key.
Map key should be generate on same system where you are running application.
Also check whether you have google play account signed and location setting is enabled.
please check here for more details:
https://developers.google.com/maps/documentation/android/start

Android - Maps Cannot show

i wanna show google maps on my android application. show i do some basic step like this :
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
maps.xml
<view android:id="#+id/mv"
class="com.google.android.maps.MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:apiKey="0cNoErXkpZDlKvCYr_OFj5xZD39-***********"
/>
and this is may maps class, import and onCreate method
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
method onCreate() on maps class
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.maps);
mapView = (MapView)findViewById(R.id.mv);
mapView.setSatellite(false);
mapView.setTraffic(false);
mapView.setBuiltInZoomControls(true);
int maxZoom = mapView.getMaxZoomLevel();
int initZoom = maxZoom-2;
mapControl = mapView.getController();
mapControl.setZoom(initZoom);
latE6 = (int) (lat*1e6);
lonE6 = (int) (lon*1e6);
gp = new GeoPoint(latE6, lonE6);
mapControl.animateTo(gp);
overlayButton = (Button)findViewById(R.id.doOverlay);
but why my map didnt show, i only see the grid whithout maps, and when i try to read logcat, i see this error with yellow color
Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher#40563470
please help me. thanks mate
Are you sure your API key is correct? When the API key doesn't match, it shows the grid instead of the map.
Running the app from Eclipse directly on the emulator / an actual phone requires a different key then when you build the .apk file first and run that on a device.
-If you have internet over proxy you will get grids .
-Use the default debug keystore for generating API key and try .

Categories

Resources