Cannot display Google Maps - android

I am trying to create my first Google Maps in Android using an emulator in Eclipse with no success. All I get for the map is a gray tiled screen that I can zoom but there is no map there. Below is my AndroidManifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.herb2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.herb2.Herb2Activity"
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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key is not shown here" />
</manifest>
Below is my layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/latitude_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude: " />
<TextView
android:id="#+id/longitude_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: " />
<com.google.android.maps.MapView
android:id="#+id/mapvw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="my key is not shown here"
android:clickable="true"
android:enabled="true" />
</LinearLayout>
Finally below is my java source:
public class Herb2Activity extends MapActivity {
private TextView latitudeView;
private TextView longitudeView;
private LocationManager locationManager;
private MapController mapController;
private MapView mapView;
private GeoPoint point;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_herb2);
latitudeView = (TextView) findViewById(R.id.latitude_view);
longitudeView = (TextView) findViewById(R.id.longitude_view);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mapView = (MapView) findViewById(R.id.mapvw);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapController = mapView.getController();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
3600, 1000, new LocationListener() {
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void onLocationChanged(Location loc) {
if (loc != null) {
int lt = (int) (loc.getLatitude());
int lg = (int) (loc.getLongitude());
latitudeView.setText("Latitude is: "
+ String.valueOf(lt));
longitudeView.setText("Longitude is: "
+ String.valueOf(lg));
int latit = (int) (loc.getLatitude() * 1E6);
int longit = (int) (loc.getLongitude() * 1E6);
point = new GeoPoint(latit, longit);
mapController.animateTo(point);
mapController.setZoom(15);
}
}
});
}
#Override
protected boolean isRouteDisplayed() {
return true;
}
#Override
protected boolean isLocationDisplayed() {
return false;
}
}
I am suspecting it may have something to do with my API key which I generated from Google. I provided the SHA1 certificate fingerprints to generate my key. I added at the end of the key my package name which is com.example.herb2 as shown above. I also made sure I was using a Google API device as my emulator. I assume the MD5 fingerprint is used for production. I will appreciate any help on why my map shows nothing but gray.

Have you looked at Google map signed api key errors in Android?
It most probably is that you're using a signed key instead of a debug key.

Related

The meta-data tag does not have right value in googlemap v2

i am trying to use Google Maps in my application using google play services. getting errors
"java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 but found 5077000. You must have the following declaration within the element: "
but i was added it and no solution , what's wrong
MainActivity
public class MainActivity extends FragmentActivity implements OnClickListener,
android.location.LocationListener{
GoogleMap map;
Button bmap, bsatelite, bhybrid;
TextView header;
LatLng my_Position = new LatLng(0, 0);
LatLng my_prev_Position = new LatLng(0, 0);
double my_Latitude = 0;
double my_Longitude = 0;
LocationManager locationManager;
int location_findcounter = 0;
String provider = "";
Boolean Start;
static boolean placeshow = false;
HashMap<String, String> mMarkerPlaceLink = new HashMap<String, String>();
CheckBox chckboxanimatetomylocation;
Marker mark;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bmap = (Button) findViewById(R.id.btnMap);
// header = (TextView) findViewById(R.id.header);
bsatelite = (Button) findViewById(R.id.btnsatelite);
bhybrid = (Button) findViewById(R.id.btnhibrid);
chckboxanimatetomylocation=(CheckBox)findViewById(R.id.checkBoxanimatetomylocation);
bmap.setOnClickListener(this);
bsatelite.setOnClickListener(this);
bhybrid.setOnClickListener(this);
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getBaseContext());
if (status != ConnectionResult.SUCCESS) { // Google Play Services are
// not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
requestCode);
dialog.show();
} else {
//SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
// .findFragmentById(R.id.map);
// Getting Google Map
// map = fragment.getMap();
map.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
#Override
public boolean onMyLocationButtonClick() {
// TODO Auto-generated method stub
map.moveCamera(CameraUpdateFactory.newLatLng(my_Position));
map.animateCamera(CameraUpdateFactory.zoomTo(17));
return false;
}
});
}
if (map != null) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
bsatelite.setEnabled(true);
bsatelite.setTextColor(Color.BLACK);
bhybrid.setEnabled(true);
bhybrid.setTextColor(Color.BLACK);
map.setMyLocationEnabled(true);
Start = true;
// Getting LocationManager object from System Service
// LOCATION_SERVICE
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location From GPS
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
} else {
Toast.makeText(getApplicationContext(),
"Please make The GPS ON", Toast.LENGTH_LONG).show();
}
}
}
the main layout
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
tools:context="com.Dawarly.Main_activity" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/checkBoxanimatetomylocation"/>
</RelativeLayout>
the mainifist file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Walkwithme.View"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission
android:name="com.Walkwithme.View.MAPS_RECIEVE"
android:protectionLevel="signature" >
</permission>
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<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="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library 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="AIzaSyCBv2SIJN6_sIqI_68iu8yYFnsRBDQVie4" />
<activity
android:name="MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="About"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:value="com.Walkwithme.View.MainActivity" >
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.Walkwithme.View.MainActivity" />
</activity>
</application>

Highlight area in Google Maps v2

How can I highlight an area/region on Google Maps v2 Android? I also have a list of geopoints of that particular region. It needs to highlight that region when you scroll to that region. It needs to fill color for nearby region to differentiate from each other so each region should have a different color.
You need to draw a polygon by selecting some points on map. Here is the code.
MainActivity.java
public class MainActivity extends FragmentActivity implements
OnMapClickListener,
OnMapLongClickListener,
OnMarkerClickListener {
private GoogleMap myMap;
Location myLocation;
boolean markerClicked;
PolygonOptions polygonOptions;
Polygon polygon;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager manager = getSupportFragmentManager();
SupportMapFragment mapFragment = (SupportMapFragment) manager
.findFragmentById(R.id.map);
myMap = mapFragment.getMap();
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.setOnMapClickListener(this);
myMap.setOnMapLongClickListener(this);
myMap.setOnMarkerClickListener(this);
markerClicked = false;
}
#Override
public void onMapLongClick(LatLng point)
{
myMap.addMarker(new MarkerOptions()
.position(point).title(point.toString()));
markerClicked = false;
}
#Override
public boolean onMarkerClick(Marker marker)
{
if(markerClicked)
{
if(polygon != null)
{
polygon.remove();
polygon = null;
}
polygonOptions.add(marker.getPosition());
polygonOptions.strokeColor(Color.BLACK);
polygonOptions.strokeWidth(5);
polygonOptions.fillColor(0x884d4d4d);
polygon = myMap.addPolygon(polygonOptions);
marker.remove();
}
else
{
if(polygon != null)
{
polygon.remove();
polygon = null;
}
polygonOptions = new PolygonOptions().add(marker.getPosition());
markerClicked = true;
marker.remove();
}
return true;
}
#Override
public void onMapClick(LatLng point)
{
Toast.makeText(getApplicationContext(),
"Long Press to select locations", Toast.LENGTH_LONG).show();
}
}
activity_main
<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=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
manfiest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.polygononmap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.googlemapwithsession.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="google.map.ver2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.polygononmap.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="your api key" />
</application>
</manifest>
now use long press to select points on map and click on marker will draw polygon accordingly.. I thing this will help.
http://www.youtube.com/watch?v=YEM90r9r9vI
for details https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polygon
You just draw a Polygon on your map and fill it with the color you need.

google map display

I am getting problem in google map screen, it display blank google map screen contains tiles in whole screen map is not being generate
I have done every settings proper, as per getting solution from net for same problem still I cannot resolve problem pls anyone can help me for this ?
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmaptest5"
android:versionCode="1"
android:versionName="1.0" >
<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="com.example.gmaptest5.Gmap5MainActivity"
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:name="com.google.android.maps"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY API KEY"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<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"/>
<permission
android:name="com.example.gmaptest5.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gmaptest5.permission.MAPS_RECEIVE"/>
</manifest>
Main.xml
<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/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="MY API KEY" />
</LinearLayout>
Main.Java
public class Gmap5MainActivity extends MapActivity {
private MapView myMapView;
LocationManager locationManager;
private Location myLocation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gmap5_main);
myMapView = (MapView)findViewById(R.id.mapview1);
double lat = 19.7888;
double longi = 52.535;
GeoPoint p = new GeoPoint((int) (lat *1E6),(int) (longi *1E6));
//GeoPoint p = new GeoPoint((int) (location.getLatitude()* 1000000), (int) (location.getLatitude()* 1000000));
MapController mc = myMapView.getController();
mc.setZoom(18);
mc.animateTo(p);
// Enable Sattelite-Mode
myMapView.setSatellite(true);
myMapView.getMapCenter();
myMapView.setBuiltInZoomControls(true);
myMapView.displayZoomControls(true);
myMapView.invalidate();
myMapView.getOverlays();
myMapView.getProjection();
this.myLocation = new Location("gps");
this.myLocation.setLongitude(77.52436144125092);
this.myLocation.setLatitude(13.05096452223662);
Double lat1 = myLocation.getLatitude();
Double longi1 = myLocation.getLongitude();
GeoPoint point = new GeoPoint(lat1.intValue(), longi1.intValue());
mc.setCenter(point);*/
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_I) {
myMapView.getController().setZoom(myMapView.getZoomLevel() + 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_O) {
myMapView.getController().setZoom(myMapView.getZoomLevel() - 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_S) {
myMapView.setSatellite(true);
return true;
} else if (keyCode == KeyEvent.KEYCODE_T) {
myMapView.setSatellite(false);
myMapView.setTraffic(true);
return true;
}
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_gmap5_main, menu);
return true;
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
Your are mixing Google Map API V1 with API V2, if you want to use Google Map V2 as it looks by your Manifest file then you can check this blog post I wrote on how to add a Google map API V2 to your application:
Google Map API V2 Android
if you want to use API V1 then you will have to change your Manifest file as it currently set to use API V2, follow this link:
https://developers.google.com/maps/documentation/android/v1/hello-mapview

Need to place an icon on my google map in an android application using GPS coordinates

Thanks in advance, I'm having dificulties trying to display an icon on my current location in a mobile application using google maps. At the moment I'm able to retrieve the maps from Google maps android api v2 libraries using the using API key etc., and I am able to retrieve my own location on GPS coordinates, "latitude" and "longitude" as they can be displayed on the screen in two textViews in my mobile device. My problem now is how to use those coordinates to display with an icon my own location on the map. Obviously I'm doing something wrong when I try to implement it. I tried to implement it using overlays but I'm having plenty of errors. I don't know why or what way to take.
Here is my code. Any help I would really appreciate it.
thanks
This is my MainActivity.java
package com.example.location3;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.TextView;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
TextView textLat;
TextView textLong;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create reference
textLat = (TextView) findViewById(R.id.textLat);
textLong = (TextView) findViewById(R.id.textLong);
// create locationManager object
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// create LocationListener object (listen for changes in the location)
LocationListener ll = new myLocationListener();
// use lm location manager to get update
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
// create a LocationListener to do what we want
class myLocationListener implements LocationListener {
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// implemented method
#Override
public void onLocationChanged(Location location) {
if (location != null) {
// variables to get and store longitude and latitude
double pLong = location.getLongitude();
double pLat = location.getLatitude();
// set text to display values from longitude and latitude
textLat.setText(Double.toString(pLat));
textLong.setText(Double.toString(pLong));
}
}
// implemented method
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
// implemented method
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
// implemented method
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
This is my Activity_main.xml
<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=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitud"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textLat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textLong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textLat"
android:text="Longitud"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
And this is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.location3"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.location3.permissions.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.location3.permission.MAP_RECEIVE" />
<!-- to be able to use it for mobiles -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<!-- Permision to use Internet to get the maps -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Permision for the cache which is done in the external memory -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Permision to use google services -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Permision to be able to point in the map where the user is -->
<!-- Permision to use wifi net -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Permision to use GPS -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library
android:required="true"
android:name="com.google.android.maps" />
<activity
android:name="com.example.location3.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>
<!-- API provided from Google -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCx00iNUdhMi9uyuCO9tTPwX4-nbi4wg6wx" />
</application>
</manifest>
you need to create a class which will handle the overlay wherever you want to pinup on the map. refer this tutorial here
try this :
class CurrentLocationOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
public CurrentLocationOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CurrentLocationOverlay(Drawable defaultMarker , Context context) {
this(boundCenterBottom(defaultMarker));
}
#Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
#Override
public int size() {
return mapOverlays.size();
}
public void addOverlay(GeoPoint gp , String title , String msg) {
OverlayItem overlay = new OverlayItem(gp, title, msg);
mapOverlays.add(overlay);
this.populate();
}
}
add icon :
Drawable mDrawable = getResources().getDrawable(R.drawable.pinpoint);
GeoPoint point = new GeoPoint((int)(lat* 1E6) , (int)(lng* 1E6));
CurrentLocationOverlay currentLocationOverlay = new CurrentLocationOverlay(mDrawable);
currentLocationOverlay.addOverlay(point ,"" , "");
mapView.getOverlays().add(currentLocationOverlay);

error application when show map

I'm new to android
I'm trying make a simple app in android with google map, but when I run it in emulator look error
The Application MapGoogle (process com.jol.android.Mapgoogle) has stopped unexpectedly. Please try again.
This is my GoogleMap.java
package com.jol.android.Mapgoogle;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.RelativeLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class Googlemaps extends MapActivity {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main); // bind the layout to the activity
// create a map view
RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mapview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mapController = mapView.getController();
mapController.setZoom(14); // Zoon 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler());
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
public class GeoUpdateHandler implements LocationListener {
#Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
mapController.animateTo(point); // mapController.setCenter(point);
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jol.android.Mapgoogle"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name=".mapgoogle"
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" />
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
This my main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0Qe1BE05sZZFeWkfqemBVn-tw_Y_Kc9E40HpY-w" />
</RelativeLayout>
But when I run this program I got this error
The Application MapGoogle (process com.jol.android.Mapgoogle) has stopped unexpectedly. Please try again.
Why like this? Please help me. Thank you, mate.
Try this
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
mobiForge: Using Google Maps in Android
You have several problems, the main one being the line:
RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mapview);
It's an illegal cast and it does nothing - get rid of it!
As a matter of style your package should be all lower case, make it
package com.jol.android.mapgoogle;
Make sure you compilation unit is called Googlemaps.java and that it matches the class name.
As other posters have pointed out, you need certain permissions in the manifest. This manifest should work and match the other changes I have mentioned.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jol.android.mapgoogle"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-sdk android:minSdkVersion="9" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Googlemaps"
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:name="com.google.android.maps"
android:required="true" >
</uses-library>
</application>
</manifest>
.
You need to add following tag in your manifest file
<application >
<activity>
<uses-library android:name="com.google.android.maps" />
</activity>
</application>
Put this in the manifest:
<uses-permission android:name="android.permission.INTERNET">

Categories

Resources