Unable to pan or move the osmdroid map - android

I'm using the osmdroid map in a sample application. The map is seen,zoom works,and everything is fine except that i'm unable to pan/move the map.
My main xml code is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.osmdroid.views.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
</org.osmdroid.views.MapView>
</RelativeLayout>
My java code is:
public class MapTest extends Activity {
private MapView mapView;
private MapController mapController;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_test);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(false);
mapView.setMultiTouchControls(true);
mapController = this.mapView.getController();
mapController.setZoom(10);
GeoPoint mapCenter = new GeoPoint(17.4467, 78.4667);
mapController.setCenter(mapCenter);
}
}
Any ideas as to how to enable the movement?

Try removing:
android:clickable="true"
from your MapView. That makes the MapView consume touch events and it messes with the dispatchTouchEvent method. You might also try removing the focusable stuff too.

mapView.setClickable(false);
It worked for me.
You should give it a shot.

Just install previous version for now, looks like there's a bug in 3.0.9.

Try to use
mapView.setClickable(false);

Related

How to display a map Frame above PanoramaGL-Activity

I use the PanoramaGL Library (https://code.google.com/p/panoramagl/) to display spheric 360° Images.
What I want:
The top half of the screen should contain a OSMdroid-Map (https://osmdroid.net/) and the bottom half shows panoramic images with PanoramaGL like this:
Problems:
You create panoramic Views in PanoramaGL using the class PLView which extends Activity.
If you show a panoramic image it always occupies the whole screen, and I see no way to change the layout. As soon as I try to define any xml-Layout, the panoramic image does not show up anymore.
My current code, where the map-part is commented out, so that only the panoramic image is displayed:
package com.example.campusnav;
//lots of imports...
public class MainActivity extends PLView {
private MapView mMapView;
private MapController mMapController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*setContentView(R.layout.activity_main);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mMapController = (MapController) mMapView.getController();
mMapController.setZoom(13);
GeoPoint startPoint = new GeoPoint(52.432846, 8.369147);
mMapController.setCenter(startPoint);*/
PLSpherical2Panorama panorama = new PLSpherical2Panorama();
panorama.setImage(new PLImage(PLUtils.getBitmap(this, R.raw.p_1), false));
this.setPanorama(panorama);
}
}
Any suggestions how to work around this problem? Is there a way to display two seperate activities arranged in a vertical layout?
yes you can display both Panorama and map together
Extend your activity from PLView
XML
<RelativeLayout
android:id="#+id/rl_streetview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#00FF40" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_mapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_streetview"
android:layout_margin="0dp"
android:layout_weight="1" >
<fragment
android:id="#+id/location_map"
android:layout_width="match_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Activity
#Override
protected View onContentViewCreated(View contentView) {
ViewGroup mainView = (ViewGroup) this.getLayoutInflater().inflate(R.layout.activity_main, null);
rl_streetview = (RelativeLayout) mainView.findViewById(R.id.rl_streetview);
rl_mapview = (RelativeLayout) mainView.findViewById(R.id.rl_mapview);
}

Android Google maps transparency

I'm working on a mapping app. And I want to show some views under the MapView.
I'm using the method:
mapView.setAlpha(0.5f);
Nothing happens to the mapView. When I try to apply this method to my buttons it works fine, even applying it to the parent view of the mapView makes every child view transparent except for the mapView.
How can we make the mapView transparent? I have looked into other questions here and I cant seem to find a solution.
Is there some special method in the mapView.getMap() that we can use to make it transparent?
You can set the transparence for the map using View.setAlpha() (documentation). Here is a working example:
activity_maps.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">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="THIS TEXT IS VISIBLE"
android:textSize="24sp"
android:gravity="center"/>
<fragment
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" />
</RelativeLayout>
MapsActivity.java
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
Marker m = googleMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
m.showInfoWindow();
View v = getSupportFragmentManager().findFragmentById(R.id.map).getView();
v.setAlpha(0.5f); // Change this value to set the desired alpha
}
}
The result looks like this (as you see the text is visible because of the map's transparency):
You can do this through the setAlpha(float) method of your MapView reference, like this:
mMapView = (MapView) findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
mMapView.setAlpha(0.5f);
If you are using MapFragment, then just use setAlpha(float) for your MapFragment.
Use a Framelayout where you put your 2 Views (CameraView and MapView) over themselfes.
And use the xml attribute alpha to make the MapView transparent.

MapView not working properly inside fragment android

Hi in my application i m displaying one fragment. Inside that fragment I am displaying map. So my code looks like :
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/innerrelativelay"
android:padding="10dp">
<TextView
android:id="#+id/storename"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Store Name:"
android:textSize="15sp"
/>
<TextView
android:id="#+id/storeaddress"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/storename"
android:text="Store Address:"
android:textSize="15sp"
/>
</RelativeLayout>
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mapView"
android:layout_below="#+id/innerrelativelay"
/>
</RelativeLayout>
and fragment looks like :
public class MyAccount extends SherlockFragment {
MapView map;
GoogleMap mMap;
TextView storeName,storeAddress;
SharedPreferences storeInfo,authenticationInfo;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.maplayout, container, false);
map = (MapView) v.findViewById(R.id.mapView);
map.onCreate(savedInstanceState);
mMap = map.getMap();
map.onCreate(savedInstanceState);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.setMyLocationEnabled(true);
try {
MapsInitializer.initialize(this.getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
mMap.animateCamera(cameraUpdate);
mMap.setMyLocationEnabled(true);
storeName = (TextView)v.findViewById(R.id.storename);
storeAddress = (TextView)v.findViewById(R.id.storeaddress);
storeInfo = getActivity().getSharedPreferences(CommonSharedPref.QCMERCHANT_STOREID, 0);
authenticationInfo = getActivity().getSharedPreferences(CommonSharedPref.QCMERCHANT_AUTHENTICATION_INFO, 0);
storeName.setText(storeName.getText().toString()+storeInfo.getString(CommonSharedPref.QCMERCHANT_STORENAME, ""));
storeAddress.setText(storeAddress.getText().toString()+storeInfo.getString(CommonSharedPref.QCMERCHANT_ADDRESS1, "")
+"\n"+storeInfo.getString(CommonSharedPref.QCMERCHANT_ADDRESS1, ""));
return v;
}
}
It shows me map properly but creating marker, showing current location or move camera at given location not working properly.
How to do this. Need help. Thank you.
UPDATE
Try changing the layout of fragment as
<fragment
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
Also it seems you havent initialised the markers yet. Thats why markers arent visible..
If you need pointers of how to do it.. There is a very good tutrial page...
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
From here https://developers.google.com/maps/documentation/android/v1/hello-mapview, you can see that
Version 1 of the Google Maps Android API as been officially
deprecated as of December 3rd, 2012
So you shouldn't use MapView anymore. I suggest you use a MapFragment instead. See the excellent documentation for it here: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

Multiple maps (with swiping) in a MapActivity in android

I have a listview of addresses in screen#1. On click of any item navigating to next screen which shows the map of clicked address. Now i want to swipe the screen to view the map of next address. Here is my code..
This is my map_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayoutTopBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/scarlet"
android:gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/textViewTopBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="Map"
android:textColor="#color/white"
android:textSize="20dp" />
</LinearLayout>
<com.xxx.android.yyyy.activities.HorizontalPager
android:id="#+id/horizontal_pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</com.xxx.android.yyyy.activities.HorizontalPager>
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/button123" />
This is my map.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
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:apiKey="xxxxxxxxxxxxxxxxxxxxx"
android:clickable="true" />
</LinearLayout>
Activity :
public class MyMapActivity extends MapActivity
{
private MapView mapView;
private Drawable mapMarker;
private MyLocationOverlay myMap;
private MapController mapController;
private List<Overlay> overlayList;
private HorizontalPager hPager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_screen);
hPager = (HorizontalPager) findViewById(R.id.horizontal_pager);
View inflatedView;
for (int i = 0; i < listViewSize; i++) //// getting listviewSize from intent extras
{
inflatedView = (View) View.inflate(MyMapActivity.this, R.layout.map, null);
mapView = (MapView) inflatedView.findViewById(R.id.mapview);
showMap(latt, longt); //getting all the latt, longt values of addresses from previous activity
hPager.addView(inflatedView);
}
hPager.setCurrentScreen(selectedAddressIndexInListView, false); //<<---- intent extras
}
void showMap(double latitude , double longitude )
{
mapView.setBuiltInZoomControls(true);
mapMarker = getResources().getDrawable(R.drawable.map_marker);
overlayList = mapView.getOverlays();
myMap = new MyLocationOverlay(this, mapView);
myMap.enableMyLocation();
mapController = mapView.getController();
GeoPoint geoPoint = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
mapController.animateTo(geoPoint);
mapController.setZoom(12);
OverlayItem overlayItem = new OverlayItem(geoPoint,"xxx", "yyy");
CustomPinpoint customPinpoint = new CustomPinpoint(mapMarker,MyMapActivity.this);
customPinpoint.insertPinpoint(overlayItem);
overlayList.clear();
overlayList.add(myMap);
overlayList.add(customPinpoint);
}
#Override
protected void onResume() {
super.onResume();
myMap.enableCompass();
myMap.enableMyLocation();
}
#Override
protected void onPause() {
super.onPause();
myMap.disableCompass();
myMap.disableMyLocation();
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
{ Reference : https://github.com/ysamlan/horizontalpager/tree/master/src/com/github/ysamlan/horizontalpager }
App is immediately force closing on click of any listview item..
Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
Where iam going wrong? Everything works fine in following two cases.. 1. if i iterate the for loop only one time. 2. if i remove map view related lines from xml, activity files.
How can i have multiple maps in a single MapActivity with swiping?. Please help me
You can have only one Mapview per map activity, however, you can have multiple map activities in one application, which in your case wouldnt be a very ideal solution.
What you should do instead of having a totally new mapview for an address, you could have a different set of overlays for them. This way you'll only need to change the set of overlays when you want to view map details for another address. Besides being possible to make this with Android, its much more optimal than having multiple mapviews.
So far I know Currently Android supports only one MapView per MapActivity.

Google map application

I am trying to do a google map related application.While doing that application i got some problems.This is my xml file
< LinearLayout 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:enabled="true"
android:clickable="true"
android:apiKey="0uw2roKAecBgrtyYUPVL-pJ84Ez4tfHTilFZCGw"/>
<LinearLayout android:id="#+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</LinearLayout>
And this is my .java file
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
}
I am getting google map view for this application but no zoom.
If i change first to i am getting output with zoom options..what is the problem with the linear layout.Pls tell me friends
First thing Change your outermost layout to Relative as I thought you want to use.
The problem with LinearLayout is that you forgot to place the weight.
Give theandroid:layout_weight="1" to mapview and android:layout_weight="0" to zooom control layout.
to control zoom, panning and other actions you need to define
MapController mapController = mapView.getController();
:)
Try this in onCreate:
mapView.setBuiltInZoomControls(true);

Categories

Resources