LinearLayout maplayout = new LinearLayout(this);
maplayout.setGravity(Gravity.BOTTOM);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,600);
MapView mapView = new MapView(this,mapkey);
MapController mc = mapView.getController();
mc.setZoom(20);
maplayout.addView(mapView,params);
setContentView(maplayout);
I got a mapview with a specified location by using the above code and its run successfully but
When i swipe in map it doesnt move.. its APK level 8 project
Add this to your mapview in xml,
android:clickable="true"
Or, Add this in your Java file,
mapView.setClickable(true);
Related
I am using a map fragment to show a map. But when the map starte it shows some location in africa and then shifts to the place i wanted. i have tried few solutions in the stackoverflow, which didnt work, it still starts from africa
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(26.588527, 77.519531));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(4);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
another solution:
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.588527, 77.519531), 4));
You can configure initial map state:
using cameraTargetLat, cameraTargetLng, cameraZoom XML attributes, e.g.:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="26.588527"
map:cameraTargetLng="77.519531"
map:cameraZoom="4"/>
programmatically using GoogleMapOptions, e.g.:
CameraPosition indiaPosition = new CameraPosition.Builder()
.target(new LatLng(26.588527, 77.519531))
.zoom(4)
.build();
GoogleMapOptions mapOptions = new GoogleMapOptions().camera(camera)
SupportMapFragment map = SupportMapFragment.newInstance(mapOptions);
Try this:
//setting India region in google maps
LatLngBounds INDIA = new LatLngBounds(
new LatLng(7.2, 67.8), new LatLng(36.5, 93.8));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(INDIA.getCenter(), 5));
this would set India region on the map.
Try this :
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(26.588527, 77.519531), 11.5f), 4500, null);
works very well !!
Android: While creating Map
I am getting the Blank page.I have a valid API key also and set it in Manifest.
my activity.
relativeLayout = new RelativeLayout(context);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relativeLayout.setLayoutParams(layoutParams);
GoogleMapOptions googleMapOptions = new GoogleMapOptions();
googleMapOptions.mapType(GoogleMap.MAP_TYPE_NORMAL)
.compassEnabled(false).rotateGesturesEnabled(false)
.tiltGesturesEnabled(false);
googleMapOptions.camera(new CameraPosition(new LatLng(0, 0), 3, 0,
0));
mapView = new MapView(context, googleMapOptions);
mapView.onCreate(new Bundle());
relativeLayout.addView(mapView);
Double[][] latlang = mapData.getLatlang();
marker = new Marker[mapData.getLatlang().length];
for (int i = 0; i < mapData.getLatlang().length; i++) {
this.marker[i] = mapView.getMap()
.addMarker(
new MarkerOptions()
.position(
new LatLng(latlang[i][0],
latlang[i][1]))
.title(" ")
.snippet(" "));
}
I had the same issue, because I was creating the MapView inside a Fragment and forgot to add the onResume method to the fragment code.
mapView map = new MapView(getActivity(), options));
map.setClickable(true);
map.onCreate(savedInstanceState);
map.onResume();
Hope this helps someone
Add setContentView(relativeLayout); after this line relativeLayout.addView(mapView); It'll solve your problem.
I use osmdroid which is based on Google Map API v1. When I zoom in/out the map my markers are scaling accordingly but I want them to have fixed size. So how can I prevent scaling of a Drawable (used as a marker of OverlayItem) when I zoom in/out the map?
I create Drawable for the marker using BitmapDrawable(scaledBitmap)
for fix size u add a popupview on a geopoint which is fix size by setting view params and set this drawable as a background
View popUp = getLayoutInflater().inflate(R.layout.map_popup, map, false);
MapView map = (MapView) findViewById(R.id.mapview);
MapView.LayoutParams mapParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
<geopoint>,
<x offset if required>,
<y offset like pinHeight>,
MapView.LayoutParams.BOTTOM_CENTER);
map.addView(popUp, mapParams);
I am using the following code for showing the marker in the current location...but when i change the orientation of the device marker disappears..?
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = Activity.this.getResources().getDrawable(R.drawable.icon);
MyItemizedOverlay itemizedOverlay = new MyItemizedOverlay(drawable ,Activity.this);
GeoPoint point = new GeoPoint( (int)(location.getLatitude()*1000000),
(int)(location.getLongitude()*1000000));
OverlayItem overlayitem = new OverlayItem(point, "Current Location :","+acTextView.getText());
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
MapController mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(14);
How to handle the orientation in the mapview..?
Actually, when orientation of device changes the Activity restart..I put the following attribute in my manifest.xml and my problem is solved now :
android:configChanges="orientation"
I'm trying to read a map from a link (http://maps.google.com/maps/ms?msid=216892338463540803496.000494dd57eb5ebce6db2&msa=0) and plot it on a MapView, is it possible?
As you posted more information in my previous answer ("but I don't want to parse the KML and plot point by point. I was wondering if theres a way to plot all at once"), I can now redifine my answer.
You should try these lines and adapt it to your needs:
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
Uri uri1 = Uri.parse("geo:0,0?q=http://code.google.com/apis/kml/
documentation/KML_Samples.kml");
mapIntent.setData(uri1);
startActivity(Intent.createChooser(mapIntent, "Sample"));
Unfortunately, you won't have any control, as this is not a MapActivity.
If you plan to add more stuff on your map, you have to try my first proposal and parse yourself the kml!
Similar question: How to use kml file on mapView in Android
You can draw on the Map with Overlays
Look at this tutorial: http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/
#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.icon);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
GeoPoint point = new GeoPoint(30443769,-91158458);
OverlayItem overlayitem = new OverlayItem(point, "Laissez les bon temps rouler!", "I'm in Louisiana!");
GeoPoint point2 = new GeoPoint(17385812,78480667);
OverlayItem overlayitem2 = new OverlayItem(point2, "Namashkaar!", "I'm in Hyderabad, India!");
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
}