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));
Related
I have recently started working on an android application that includes the GPS tracking of the user's position.
For that purpose I have gone through Google's guide to setting up the GoogleMaps API for Android and I have (to my knowledge) fully understood the steps it took me to get here including the correct API_KEY and the SHA1 Footprint for the debug version of google maps.
The included code sends a request for the map information to google's API and upon loading fully sets up the map and places a marker in Sydney.
But it doesn't place the marker. Or move the maps interface to Sydney. It just shows the map and appears to be centering itself around africas west-coast every time for some reason.
Here's how far i've gotten in the Java Activity code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pkw__route__content__gps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
try {
mapFragment.getMapAsync(this);
}
catch(NullPointerException npe){
npe.printStackTrace();
}
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
current = mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
The fragment looks as follows:
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="257dp"
android:layout_height="224dp"
android:layout_marginStart="72dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="72dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".MapsActivity" />
I have added the API key to the Manifest in a tag called "com.google.android.geo.API_KEY". I will not post it in here for obvious reasons.
As said, the Map initializes correctly but the Markers are not placed and the moveCamera call is also not executed correctly
EDIT:
I think this question needs some more backstory, I am using the Map inside a fragment which is integrated into another activity.
The reason why I think this is important is because I have tried to start the map activity through an intent in which case it will fully load up, place markers and work interactively as it should. Because all of this is in the onCreate() method. How do I do this without having to invoke the Activity and stop the other one?
The map is not loaded when onMapReady(GoogleMap googleMap) is called. You have to wait for the OnMapLoadedCallback Event.
You have set a OnMapLoadedCallback to the map in onMapReady(GoogleMap googleMap) and set the marker and zoom the map to the location in this callback.
I need to show world map on my application.
I tried to use MapView and set liteMode= true and zoomLevel=1 but its not working as i need. Also groundOverlay not supported in liteMode and i need to show multiple groundOverlay on WorldMap.
can anyone know about it?
Please refere below link i need to show full world map like this.
https://upload.wikimedia.org/wikipedia/commons/b/b0/World_location_map_%28equirectangular_180%29.svg
Below code i done :
<com.google.android.gms.maps.MapView
android:id="#id/mapView"
android:layout_width="match_parent"
android:layout_height="#dimen/dp_180"
map:liteMode="true"
map:cameraZoom="1"
map:mapType="normal"
/>
In my Java Class
#Override
public void onMapReady(GoogleMap googleMap) {
if (googleMap != null) {
this.googleMap = googleMap;
this.googleMap.getUiSettings().setCompassEnabled(false);
this.googleMap.getUiSettings().setAllGesturesEnabled(false);
this.googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
this.googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.style_json));
this.googleMap.getUiSettings().setMapToolbarEnabled(false);
this.googleMap.getUiSettings().setCompassEnabled(false);
this.googleMap.getUiSettings().setScrollGesturesEnabled(false);
}
In this is added zoomLevel=1 but in google map its not showing world map as like above image link i shared.
CameraPosition cameraPosition = new CameraPosition.Builder().
target(YourLocationPoint).
tilt(60).
zoom(15).
bearing(0).
build();
myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
You can use tilt and bearing for achieving same Doc
Set style for Google map , in onMapReady of your activity.
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getActivity(), R.raw.customized_map_style));
you need to download the style. please go through below link
https://developers.google.com/maps/documentation/android-sdk/styling
update the styles as you wish.
I want to display multiple maps in my layout.
In my fragment I have a list view, in the list view item I have a mapView
<com.google.android.gms.maps.MapView
android:id="#+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
In the adapter file, in my get view method I do :
holder.mapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap googleMap) {
LatLng sydney = new LatLng(-33.852, 151.211);
googleMap.addMarker(new MarkerOptions().position(sydney)
.title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
holder.mapView.onResume();
}
});
But nothing shows up.
I have created a google maps API key, and added the following to my manifest.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="my api key, not restricted"/>
And I have added this dependency in the griddle file:
compile 'com.google.android.gms:play-services-maps:10.2.1'
Do you know why there is no map showing?
Go to :
file - new - google - Google Maps Activity and Understand the things.
Add this in your xml
tools:context="yourpackage.YourActivityName"
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
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 .