How to create a static Mapview that recognize an onTap method - android

I'm trying to develop a layout that shows a Google Map with a route drawn on a Overlay layer associated with this map. I want this mapView to be a small static map that shows, as a thumbnail, the main route the user followed, and then if the user clicks on it, an intent takes you to a different activity displaying the map in full screen with the route and all the zoom functionalities.
The thing is that although I override the onTap method of the Overlay setting there the intent to the new activity, it only works if I set the MapView as setEnabled(true), but if I do so, then the thumbnail map can be dragged and moved by the user.
I'm sorry if it is not clear enough, but I don't know how to explain it better.
Thanks in advance
This is my customized class which extends Overlay and overrides the onTap method:
class MapOverlay extends Overlay {
#Override
public boolean onTap(GeoPoint p, MapView mapView) {
Intent i = new Intent(getApplicationContext(),
RouteMapActivity.class);
startActivity(i);
return false;
};
And this is my onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detailrun_activity);
map = (MapView) findViewById(R.id.mvMain);
map.setEnabled(true);
map.setClickable(true);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = map.getOverlays();
projection = map.getProjection();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
double lat = 28.063119 * 1E6, longi = -82.41128 * 1E6;
GeoPoint point = new GeoPoint((int) lat, (int) longi);
MapController myMapController = map.getController();
myMapController.setCenter(point);
}
For now I'm only drawing a straight line between two GeoPoints, and I don't get any logcat errors.
The map with the route is indeed drawn, and the overrided onTap method works, but it seems it only recognizes the tap if my mapView is defined as enabled and clickable, but if I do so, then the user can also move and drag the map as long as he holds pressing the screen.

you can get static google map image as per your location by this link. that you can display in imageview and click on that you can target new activity which have MapView.. i think it may be a good option for you.

Related

How do I change the result of mylocationoverlay?

I am using mylocationoverlay to give my current location, however, its not exactly accurate. Sometimes it is up to 20 meters wrong. I want to be able to move the location marker to my exact position. When using the following code, when I press on the marker, the map moves and the marker stays in the same place. How do I keep the map static and allow a user to move the marker?
public class selectmap extends MapActivity {
private MapView mapView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selectmap);
mapView = (MapView) findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
final MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
mapView.getController().setZoom(17);
mapView.getOverlays().add(myLocationOverlay);
mapView.postInvalidate();
}
}
You have to write your own implementation to handle this scenario. Here is an example application where you can move the markers
https://github.com/commonsguy/cw-advandroid/tree/master/Maps/NooYawkTouch/

Android: MapView does not react on touch events under some layers of WiFiSLAM

I am using the indoor positioning framework wifislam and have a programming question.
So far I have given a MapView by the indoorLocationView of WifiSLAM. I'm working with the following code.
final IndoorLocationManager.Configuration config = new IndoorLocationManager.Configuration();
indoorLocationManager = new IndoorLocationManager(this, config,
onServiceConnected, LOCATION_CHOICE);
indoorLocationView = indoorLocationManager.createLocationView(this,
GOOGLE_MAPS_API_KEY);
final View mapContainer = findViewById(R.id.mapcontainer);
((ViewGroup) mapContainer).addView(indoorLocationView.getView());
MapView mapView = indoorLocationView.getGoogleMapView();
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pinred);
itemizedOverlay = new AddItemizedOverlay(drawable, mapView.getContext(), sm);
mapOverlays.add(itemizedOverlay);
and the AddItemizedOverlay has following methods:
#Override
public boolean onTap(GeoPoint geopoint, MapView mapView) {
mapOverlays.clear();
// geopoint = mapView.getProjection().fromPixels((int) event.getX(),
// (int) event.getY());
// latitude
if (geopoint != null) {
this.geopoint = geopoint;
lat = geopoint.getLatitudeE6();
// longitude
lon = geopoint.getLongitudeE6();
OverlayItem overlayitem = new OverlayItem(geopoint,
"Task Position", "Derzeitige Position vom Task");
this.addOverlay(overlayitem);
}
return false;
}
My problem is now, that the onTap method does not respond or react on touching on the device. As well the onTouch event has no reaction. I think those layers above of wifislam are preventing that I can reach the MapView. Is there any possibility to reach the MapView so I can add some markers on the map?
The reason for this is that there is a transparent view on top of the Google Maps view that is showing the floorplan. Try adding a listener on the view returned by IndoorLocationView#getView, but that may screw up the pinch-zoom/panning controls; you should double-check the effect (you probably want to return false from your listener unless one of your markers has been tapped).
If that doesn't work, your best bet is to contact WiFiSLAM support with your use case so they can update their SDK to meet your needs. Looks like there's a support email address in the FAQ topic of the help section of the SDK website.

MyLocatoinOverlay disableMyLocation or use OverlayItem

I have the following functionality working in my app.
I Use MyLocationOverlay to get my current location.
I extended MyLocationOverlay in order to be able to drop a custom marker instead of the blinking blue marker.
I need help on the last requirement. I simply want a marker to stay fixed on the location that MyLocationOverlay says it found originally and not move around as it jumps from satellite to satellite.
What are my options for creating this type of user experience?
I would recommend saving off the first geopoint that gets fed into the drawMyLocation function inside the CustomLocationOverlay and using that instead of the myLocation fed to the function.
int intFirstGeoPoint = 0;
GeoPoint FirstGeoPoint;
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
if(intFirstGeoPoint == 0){
FirstGeoPoint=myLocation;
intFirstGeoPoint=1;
}else{
myLocation=FirstGeoPoint;
}
// translate the GeoPoint to screen pixels
Point screenPts = mapView.getProjection().toPixels(myLocation, null);
...
...
You could also capture this location and create a new DrawableMapOverlay that only draws this point instead of hijacking the LocationOverlay

how can i implement my own double-tap in mapview?

I have been working on an offline map using OSMdroid
I have map tiles of two zoom levels namely 12 and 15
Now the usual double tap zooms the mapview by 1 level
What i m trying to do is to setZoomLevel() as 15 after the user double taps on the map,
Is it possible?
I tried using onGestureListener , but somehow it is not working
Any hint or clues in that direction or sample codes would be a big help , Thanks
I had a similar requirement with the Osmdroid MapView, in that I didn't want it to do the 'centre on the double tapped location and zoom in' default functionality. I wanted it to pop up a Toast. In my case I had an overlay on top of the MapView, so I just had the overlay consume the double tap in its onDoubleTap method. For your purposes you could just add an overlay which draws nothing but has its own double tap functionality.
So at the end of your onCreate, you could add the overlay. This little app seems to demonstrate what you want - (you'll need to add conditional code for checking zoom level and other tinkering):
public class OsmdroidDemoMap extends Activity {
private MapView mMapView;
private MapController mMapController;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.osm_main);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapController = mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
mMapController.setCenter(gPt);
DummyOverlay dumOverlay = new DummyOverlay(this);
List<Overlay> listOfOverlays = mMapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(dumOverlay);
}
public class DummyOverlay extends org.osmdroid.views.overlay.Overlay {
public DummyOverlay(Context ctx) {
super(ctx); // TODO Auto-generated constructor stub
}
#Override
protected void draw(Canvas c, MapView osmv, boolean shadow) {}
#Override
public boolean onDoubleTap(MotionEvent e, MapView mapView) {
// This stops the 'jump to, and zoom in' of the default behaviour
int zoomLevel = mMapView.getZoomLevel();
mMapController.setZoom(zoomLevel + 3);
return true;// This stops the double tap being passed on to the mapview
}
}
If you need to manage the double-tap in an MapView, i suggest you to check this thread:
android maps: How to Long Click a Map?
You can see my answer and how i adapted mapview-overlay-manager.
you can override the zoom control with its event, for that you need to define into the xml layout or you get the zoom control from the mapview
ZoomControls zoomControls = (ZoomControls)findViewById(R.id.zoomControl);
View zoomOut = zoomControls.getChildAt(0);
zoomOut.setBackgroundDrawable(getResources().getDrawable(R.drawable.zoom_out_icon));
zoomOut.setPadding(5, 5, 5, 5);
View zoomIn = zoomControls.getChildAt(1);
zoomIn.setBackgroundDrawable(getResources().getDrawable(R.drawable.zoom_in_icon));
zoomIn.setPadding(5, 5, 5, 5);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
public void onClick(View v) {
mc.zoomIn();
mapView.invalidate();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
public void onClick(View v) {
mc.zoomOut();
mapView.invalidate();
}
});
now you can implement your own zoom control
In the latest OSMdroid library 4.0 has inbuilt automatic double tap zoom in. But nothing is better than having a zoom control.
you can use just add below line
mMapView.setMultiTouchControls(true);

android mapview overlay popup hide

i have a mapview and overlay items which when tap on shows popuo with text. what I want is when user taps on map outside of these overlay items or popup hide the popup if its currently visible.
The only way to do it (as I know), is adding new overlay to your map, witch serves as the popup. When you tap outside of the overlay, just remove it from overlay list.
This means you have to draw and handle events for your popup by yourself.
Ive been trying to acheive the same, this is exactly what i want :-
http://proxy.latest.xuemath.appspot.com/img?s=aR.1f.1be6ifej.2ec/_Fbk8IlxNQXM/S-ruq97dRWI/AAAAAAAAELY/s-o3onSReiU/s400/kml_google_maps_v3.bmp
i have implemented googleMapView with overlays, i have one issue i want to show a popup when clicked on each overlay, and when i click on another overlay the previous popus should disappear and new one should appear at the clicked location(ie projection points). And popup shouldnt appear when i click anywhere else on screen.Im using onTap event to record onclick. (map_overlay) is the layout that i want to show when someone click a projection point on the map. The code is below and map_overlay.xml could be any file.
Class: ItemizedOverlay:-
public boolean onTap(GeoPoint p, MapView mapView) {
LayoutInflater inflater = (LayoutInflater)cContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, p, LayoutParams.WRAP_CONTENT);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.map_overlay, null);
mapView.removeView(view);
mapView.invalidate();
mapView.addView(view,lp);
mapView.invalidate();
return true;
}
Below is the Main class in which im displaying projection points which is working fine and im calling I have implemented the onTap event in another class as shown above:
public class MapView extends MapActivity{
private ArrayList overlayItem ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.large_mapview);
mapView = (MapView) findViewById(R.id.mapview);
// mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mappointer2);
ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,this);
OverlayItem overlayitem;
GeoPoint point;
double lat;
double lng;
for (int i = 0; i < overlayItem.size(); i++) {
lat = Double.parseDouble(overlayItem.get(i).getLatitude());
lng = Double.parseDouble(overlayItem.get(i).getLongitude());
point = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));
overlayitem = new OverlayItem(point, i+"".toString(), overlayItem.get(i).getDetails().toString());
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
mapView.invalidate();
}
}

Categories

Resources