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
Related
I am designing an android app with Xamarin which will have an activity with google maps inside it, but i am struggling to display the map. It shows an empty box with no map display on it. Following is the code which i used for this practice.
My Activity
namespace teslin
{
[Activity(Label = "Map")]
public class MpActivity : Android.GoogleMaps.MapActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MapView);
var map = FindViewById<MapView>(Resource.Id.mapv);
map.Clickable = true;
map.Controller.SetZoom(16);
map.Controller.SetCenter(new GeoPoint((int)40.8270449E6, (int)-73.9279148E6));
}}
xml lay out
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:layout_weight="9" />
<com.google.android.maps.MapView
android:id="#+id/mapv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:apiKey="AIzaSyD-UMij5IO6ezjuFCNnF7tRoG3niaPbNEU" />
</LinearLayout>
It looks like you're using the obsolete/outdated Maps API v1. Google removed support for this last year.
Instead you want to use Android Maps API v2 (a part of Google Play Services). Xamarin has some documentation on Maps in Android. It can be a bit tricky to get Maps working in Android, so carefully read these docs. Specifically, you'll want to read the section on the Maps API.
There is an example on Github that shows how to use the Google Play Services Component to add Maps to your application.
For those who are looking for a thorough example, check out this video that demonstrates how to integrate Google Maps with Xamarin Android, hope this helps!
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));
I'm currently working on Android and have started with Google Maps V2 API.
As I have finished going through all their setup guide the map worked and I was able to see the continents. Only problem is that when I zoom in, the map stays the same I just get less pixels untill eventually I get gray squares - as if it has loaded the map but not entirely. I'd been looking around for someone with a problem like mine and couldn't find any.
Any assistance will be appreciated.
My code:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
public class myMapActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
}
More information:
I had added:
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
and gotten gray squares without map at all. hope it helps identify the problem Thank you in advance.
As recommended I had uninstalled which probably removed previous save of the map.
After reinstalling the app works fine.
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.
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 .