I implemented the app that displays the map. and it shows the particular location using latitude and longitude. but it shows an empty map.how to see the map. please can anybody help me.
code
public class mapsdemo extends MapActivity
{
MapView mapView;
GeoPoint gp;
MapController mc;
/** Called when the activity is first created. */
#SuppressWarnings({ "unchecked", "rawtypes" })
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapView.displayZoomControls(true);
List mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(drawable, this);
double lat = 17.385044;
double longi = 78.486671;
gp = new GeoPoint((int) (lat *1E6),(int) (longi *1E6));
OverlayItem overlayitem = new OverlayItem(gp, "Hello", "I'm in Hyd");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mc = mapView.getController();
mc.animateTo(gp);
mc.setZoom(13);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
main.xml
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
< com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="00YCOT71Vu0btHPPlbIR9uvF0-l4mcAVT9_6HMw"
android:id="#+id/mapView"
android:enabled="true"
android:clickable="true"
/>
< /LinearLayout>
manifeast
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maps.demo"
android:versionCode="1"
android:versionName="1.0">
< uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".mapsdemo"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<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" />
</application>
</manifest>
This is most likely caused by a signature mismatch. Make sure that you registered your private key from the keystore used to package your application with Google at the maps API signup page and ensure the key that is issued is in your layout file for the MapView.
Related
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
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
I'm trying to make application where user has an option to click on button "Find on Map".
If user clicks "Find on Map" button, I would like to start new activity that contains google map.
I did this tutorial and map shows.
http://mobiforge.com/developing/story/using-google-maps-android
However this tutorial shows map in the main activity. That is why I made ViewMap activity which is exactly the same as the main activity in the tutorial showed above.
This is how I start ViewMap activity:
findOnMapButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// create an Intent to launch the ViewMap Activity
Intent viewMap = new Intent(ViewCourse.this, ViewMap.class);
startActivity(viewMap); // start the ViewContact Activity
}
});
Here is ViewMap.java:
package com.ijankovic.exammanager;
import android.os.Bundle;
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 ViewMap extends MapActivity {
private MapView mapView;
private MapController mc;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_map);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
String coordinates[] = {"31.567615", "74.360962"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(7);
mapView.invalidate();
}
#Override
protected boolean isRouteDisplayed() {
return false; // we are not displaying route information
}
}
Here is view_map.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:apiKey="0jHJ3aWhSfOMZ1gjFMGc8xTf7mASBEtQcynZPOQ"
android:clickable="true"
android:enabled="true" />
</RelativeLayout>
I know my API key works for sure since map displays if I put ViewMap as the main activity.
However if I try to put it in activity that gets called on button clicked, map opens but everything is grey and tiles do not load. There is Google logo in the bottom left corner.
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ijankovic.exammanager"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<uses-permission android:name="android.premission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<activity
android:name="com.ijankovic.exammanager.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewCourse"
android:label="#string/app_name"></activity>
<activity android:name=".ViewMap"
android:label="#string/app_name"></activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
Problem:
Is something wrong with my Intent and ViewMap activity call?
Any suggestions are welcome. Thanks in advance!
Edit:
I managed to get google maps with this call:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY));
startActivity(i);
However this seems to start google maps app. It is not google maps within my app like the tutorial showed.
Add these 2 permissions in your manifest file Before the Internet Permission:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
And make sure your API key is correct
Add this permission in your manifest file.
<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" />
In your map activity have you defined the MapController ?
There may be possibility that you might have missed the MapView or MapController
You can use the following code in your mapactivity class
to confirm
private MapView mapView;
private MapController mc;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview1);
mc = mapView.getController();
String coordinates[] = {"31.567615", "74.360962"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(7);
mapView.invalidate();
}
Simply Copy and Paste this class in your project.I have tested in my Demo Project and it worked for me...
Hope it will work for you also .. :)
import com.google.android.maps.MapActivity;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class MyMapActivity extends MapActivity
{
private MapView mapView;
private MapController mc;
private GeoPoint geoPoint;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.view_map);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();
mc.setZoom(16);
geoPoint = new GeoPoint((int)(31.567615 * 1E6),(int)(74.360962 * 1E6));
mc= mapView.getController();
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mc.animateTo(geoPoint);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
}
I figured out what the problem was!
What I had:
<uses-permission android:name="android.premission.INTERNET" />
What it should be:
<uses-permission android:name="android.permission.INTERNET" />
So I typed premission instead of permission.
I'm surprised that eclipse does not point syntax errors in AndroidManifest.xml file.
I want to display google map in Android ,i have map API even map is not showing and also not throwing any error.
I have use following
Java code
public class GoogleMapActivity extends MapActivity {
private Location myLocation;
protected MapView myMapView = null;
protected LocationManager myLocationManager = null;
protected MapController mapController;
List<Overlay> mapOverlays;
protected boolean isRouteDisplayed() {
return false;
}
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.myMapView = new MapView(this, "0jzIB6m5R1kLa_rGte-DS9PhF3KlSgqYHUZognA");
this.setContentView(myMapView);
myMapView.setBuiltInZoomControls(true);
myMapView.setSatellite(true);
mapController = myMapView.getController();
mapOverlays = myMapView.getOverlays();
this.myLocation = new Location("gps");
this.myLocation.setLongitude(77.52436144125092);
this.myLocation.setLatitude(13.05096452223662);
updateView();
}
private void updateView() {
Double lat = myLocation.getLatitude();
Double lng = myLocation.getLongitude();
GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
mapController.setCenter(point);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googlemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".GoogleMapActivity"
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" />
</application>
</manifest>
Finally i get output blank. please have a look at below screen
on please suggest me where i'm wrong
I think you have not added myMapView in current layout ...........
you created in java code
this.myMapView = new MapView(this,
"0jzIB6m5R1kLa_rGte-DS9PhF3KlSgqYHUZognA");
but looks not added in any layout.. as per link
If you dynamically create the MapView via its constructor, you can
supply the API key that way from Java code, but then you will need to
dynamically add it to your layout.
You cannot both have the widget in your layout and set the API key
in Java.
Solutions :
option 1 - Create a Linear layout in for XML and add the myMapView
in that.
option 2 -Create Map view in XML it self and get that by
findViewById.
Try placing the mapview on the layout xml with its api key there as well and then on the activity just get a reference of the map and continue normally.
main.xml with mapView:
<com.google.android.maps.MapView android:id="#+id/mapView"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true"
android:layout_centerInParent="true" android:clickable="true" android:apiKey="YOUR MAP KEY"/>
Activity:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapView);
Below code which has working fine for me -
public class MapTabView extends MapActivity
{
MapView map;
String api = "02gY92RWvQgV-k5CUQvGPowJkw8HkN4Tmm-HDIQ";
#Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
map = new MapView(this, api);
map.setClickable(true);
map.setEnabled(true);
setContentView(map);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem menu_item)
{
switch (menu_item.getItemId()) {
case R.id.satelite:
map.setSatellite(true);
map.setTraffic(false);
break;
case R.id.traffic:
map.setTraffic(true);
map.setSatellite(false);
break;
default:
break;
}
return true;
}
}
Have a look at this TabMapsExample
I have an activity which extends MapActivity. After running the activity, the Google Map should be shown on the emulator.
How can I do that?
http://www.vogella.de/articles/AndroidLocationAPI/article.html#overview_maps
This link got what u need.
i did it. and it works for me as well..
Just move to the 4th topic from the Index. (Google Maps)
Thanks
UPDATED:
Menifest File:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.locationapi.maps" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".ShowMap" 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"></uses-library>
</application>
XML LayoutFile:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
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="Your Maps API Key"
/>
</RelativeLayout>
ACtivity:
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 ShowMap 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.mainlayout);
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) {
}
}
}
for starting mapview then follow this mapview's link
You have to signup here and then insert the code provided in your layout like this:
<com.google.android.maps.MapView
android:id="#+id/map_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="***************************************"
/>
You can refer this link, http://developer.android.com/resources/tutorials/views/hello-mapview.html
Check if you have provided your Map API key properly. This link has helped me to display the map with my present location.