google map display - android

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

Related

Google Maps API V2 Blank Map

I am trying to make a WebView application with Google Maps, but when I run it, it just shows a blank map.
This is my MainActivity.java
public class MainActivity extends ActionBarActivity {
public WebView mWB;
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
setContentView(R.layout.activity_main);
mWB = (WebView) findViewById(R.id.mWB);
mWB.setWebViewClient(new MCWC());
WebSettings webSET = mWB.getSettings();
webSET.setJavaScriptEnabled(true);
mWB.loadUrl("http://www.tomshardware.com/");
Button btnEins = (Button) findViewById(R.id.bntmap);
btnEins.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
Intent intencion = new Intent(v.getContext(),maps.class );
startActivity(intencion);
}
});
}
public class MCWC extends WebViewClient {
public boolean ShouldOverrideLoading(String url,WebView view){
view.loadUrl(url);
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (mWB.canGoBack()) {
mWB.goBack();
} else {
finish();
}
return true;
}
/**#Override public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}**/
}
return false;
}
}
This is maps.java
public class maps extends Activity implements OnMapReadyCallback {
UiSettings mapSettings;
private final LatLng GEVGELIA = new LatLng(41.1421756,22.5026124);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(GEVGELIA,15);
map.animateCamera(update);
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.setMyLocationEnabled(true);
map.setBuildingsEnabled(true);
map.addMarker(new MarkerOptions()
.position(new LatLng(41.139560, 22.503117))
.title("Korzo"))
.isVisible();
map.addMarker(new MarkerOptions()
.position(new LatLng(41.142284, 22.504579))
.title("SOU Josif Josifofski"))
.isVisible();
}
public void onMapReady(GoogleMap map) {
mapSettings.setZoomControlsEnabled(true);
mapSettings.setTiltGesturesEnabled(true);
mapSettings.setRotateGesturesEnabled(true);
mapSettings.setMyLocationButtonEnabled(true);
map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker"));
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gvglive.gvglive" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<permission
android:name="com.gvglive.gvglive.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.barcodelibrary.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 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"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".maps"
android:label="#string/app_name">
<category android:name="android.intent.category.LAUNCHER" />
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBEzDPkkL7c1VW9HS9KC8awuRsv9UpuA0M"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
maps.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
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"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context=".MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mWB">
</WebView>
<Button
android:id="#+id/bntmap"
style="?android:attr/buttonStyleSmall"
android:layout_width="55dp"
android:layout_height="55dp"
android:text="MAP"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:drawableTop="#drawable/top"
android:background="#drawable/top"/>
</RelativeLayout>
Added this to the build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
I already checked my SHA1 fingerprint and the API Key,
I even tried regenerating a new API Key,
I have to mention that when I run it from android studio to my device it shows the map, but when I generate an apk and install it, no map is shown, I've also tried both app-release and app-debug.
http://i.stack.imgur.com/ushMB.png
You can directly use the Maps services by using the Google Play Services library from the SDK importing and referring it to through the project properties. OR if you are using Android Studio, Just create your project with default Maps project.
Please see the following working code... You can copy and paste the files as it is:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.avalunjkar.mymaps" >
<uses-permission android:name="android.permission.INTERNET" />
<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 ACCESS_COARSE/FINE_LOCATION 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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MapsActivity.java
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
activitmaps.xml
<fragment 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:id="#+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Please change the package name and add your API V2 key in Strings.xml or Manifest.xml.

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.

Cannot display Google Maps

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.

MapView in android is Totally Black

i am using mapView in my application. on my emulator i am getting black screen instead this map. i have added the permissions and added the <uses-library android:name="com.google.android.maps"/>tag.When i run my app on my emulator it displays black screen instead of map.
public class MainActivity extends MapActivity {
MapView mv;
MapController mc;
GeoPoint mPoint;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mv = (MapView) findViewById(R.id.map);
mv.setBuiltInZoomControls(true);
mv.setSatellite(true);
mc = mv.getController();
mPoint = new GeoPoint(70, 30);
mc.animateTo(mPoint);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), android.R.drawable.sym_action_email);
MarkerOverlay mo = new MarkerOverlay(bitmap);
mv.getOverlays().add(mo);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
class MarkerOverlay extends Overlay{
Bitmap marker;
public MarkerOverlay(Bitmap bitmap) {
this.marker = bitmap;
}
#Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
Point p = new Point();
mapView.getProjection().toPixels(mPoint, p);
canvas.drawBitmap(marker, p.x, p.y,null);
}
}
}
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/map"
android:apiKey="0N2w90XW-PeM2vP4D4yfM2CoLRfIF6nnZAr2Cqg" />
</LinearLayout>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.overlays"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_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.overlays.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>
</application>
</manifest>
Okay. I think There was some thing wrong with my project. i delete my current project and built a new one and it worked fine.
mc.setZoom(17);
Set your zoom level they get default zoom level 1.Refer article https://developers.google.com/maps/documentation/android/v1/reference/com/google/android/maps/MapView

Categories

Resources