At middle of 2011 set mapView.setSattelite(true) will only show satellite view, but recently we find the same set will also show with roads and names above satelliete view.
May be it's very useful in other country, but in China, when add roads and names above satelliete view, the roads are not on the right position.
Can some one tell me how to remove roads and names above satelliete view?
How to show satellite view of Android mapview only.
I read Class MapView:
setSatellite(boolean on)
Sets the map mode to "satellite" mode, loading tiles of aerial imagery with roads and names superimposed.
Can someone help me out? Help us live on Mars!
public void myClickHandler(View target) {
switch(target.getId()) {
/*case R.id.zoomin:
mapView.getController().zoomIn();
break;
case R.id.zoomout:
mapView.getController().zoomOut();
break;*/
case R.id.sat:
this.mapView.setSatellite(true);
break;
case R.id.street:
this.mapView.setStreetView(true);
break;
case R.id.traffic:
this.mapView.setTraffic(true);
break;
case R.id.normal:
this.mapView.setSatellite(false);
this.mapView.setStreetView(false);
this.mapView.setTraffic(false);
break;
default:
break;
}
// The following line should not be required but it is,
// at least up til Froyo.
this.mapView.postInvalidateDelayed(2000);
}
i believe you need setStreetView, even though it says it's deprecated it works ok for me
#Deprecated
public void setStreetView(boolean on)
Deprecated. Street view availability highlighting is no longer supported. This method operates as a no-op.
Control whether Street View availability (blue outlines) is shown on the map. This is incompatible with Traffic indicators, so they will be deactivated if necessary. Street View availability can be drawn over map tiles or over satellite tiles; however, they are optimized for map tiles.
I don't believe this can be accomplished, because when you are using google mapview, the images come from google themself for road map and sattelite map, unless they do an update for the API to show only sattelite images without road names.
Related
I've an Android Application that displays a map.
The map is by default centered on the user position following its movements (the center is updated according to the position updates).
However I want the user to be able to use gestures to navigate throw the map. When the user starts the navigation I want the "following" to stop, and a button is displayed so that it can start again.
How can I know when the user has moved the map center?
On the GoogleMap.OnCameraChangeListener, I don't know if the change is due to a location changed or a user interaction.
I've a a kind of working solution using the OnCameraChangeListener, but its a bit "dirty" and I don't find it very nice:
map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition position) {
// gpsPosition contains the last position obtained
if(isFollowing && gpsPosition!=null && (Math.abs(position.target.latitude - gpsPosition.latitude)>0.000001 || Math.abs(position.target.longitude - gpsPosition.longitude)>0.000001) ){
isFollowing = false;
map.getUiSettings().setMyLocationButtonEnabled(true);
}
}
});
Is there a nice Solution to the problem?
If you want to detect user interacting with the map OnCameraChangeListener is surely too late to do that. It may be called seconds after user started interacting with the map.
What you need to do, is add 2 other listeners:
OnMyLocationButtonClickListener - to know when to start tracking (set your isFollowing to true)
OnMyLocationChangeListener - when your isFollowing is true, call GoogleMap.animateCamera to the new position
So the only thing left is when you set isFollowing to false:
Create an invisible overlay in your layout (like here, but with normal View instead of custom) and assign this overlay (the View) an OnTouchListener (ok, it is 3rd, I lied that you need only 2).
In this listener always return false, but also set isFollowing to false. This when when user starts interacting with the map and you should stop automated camera movements.
I also see you are showing and hiding my location button, so do this where you change the value of isFollowing. Btw.: good idea to do that. I'll try it too.
I have never tried this, but here are some ideas off the top of my (balding) head:
Option #1: Handle the location change updates yourself, by recentering the map yourself when the location change comes in. If a camera-change event occurs that does not appear to be tied to the location change (e.g., 5+ milliseconds later), that was presumably a user modifying the map via gestures.
Option #2: Subclass the Maps V2 MapView and override touch-related methods like onTouchEvent(). In addition to chaining to the superclass, you would know that a camera change that happens very soon from now probably is from the user modifying the map via gestures.
Option #3: Do both of the above. That way, all changes to the map should touch your code, which should increase the reliability of your determining the source of the camera change.
BTW, I filed a feature request for a better solution.
The simpliest way should be saving the center Longitude and Latitude of your Map.
Now create an EventListener and check it in an if-statement:
if(oldLongLat != newLongLat){
//Something has moved
}else {
//Nothing has moved
}
I am working on custom map app and i want to use google map tiles for background ? There is one class TileProvider in api but i don't know how to initialize it every time i try it goes something like this ?
TileProvider tileProvider=new TileProvider() {
#Override
public Tile getTile(int i, int i2, int i3) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
};
how to override getTile function to get tiles from google map server?
Any example will be appreciated ?I know getTile function need x,y and zoom value to return tile.
So quick answer is that you can get the Google Map tiles from the following URL:
http://mt1.google.com/vt/lyrs={t}&x={x}&y={y}&z={z}
Where {t} is the type of map (satellite, road, hybrid, etc) and the other attributes are specifying the coordinates and zoom level.
The possible values for {t} are as follows:
Default - m
Roads only - h
Roads simplified - r
Satellite - s
Satellite hybrid - y
Terrain - t
Terrain hybrid - p
That being said you do want to make sure what you're doing is NOT a violation of the terms & services. Specifically Google WILL allow you to cache their tiles provided that you are doing so ONLY in order to improve performance and that you delete their tiles at least every 30 days, and finally you don't pull down their tiles in an attempt to make your own mapping service.
You may want to read the Google Maps Terms of Service - https://developers.google.com/maps/terms - specifically section 10.1.1
We're porting an app from the v1 Maps API to the v2 API, and having trouble with markers.
We need markers that point in a specific geographic direction. In V1, we could build the bitmap pointing in the right direction at draw time, but in V2 the marker bitmap can't be changed.
I'm not sure if the best approach is to destroy and re-build all our markers when the map is rotated (which sounds like a performance problem), or to try drawing them all ourselves. That could be via a TileOverlay or via a view of our own that we sat on top of the map.
I don't really like any of these approaches. Has anyone tried any of them ?
UPDATE:
I've tried drawing via a view of our own, but that was far too laggy when the map was dragged.
I'm now destroying & recreating the markers, but that is (as expected) a performance problem, taking ~2000mS to update 60 markers.
Good news everyone! Google has added rotation to the Maps API, so we don't have to roll our own implementations anymore.
They have also added flat markers, which I guess is more related to the original question. A flattened marker will always stay in the orientation it was originally drawn on the map: https://developers.google.com/maps/documentation/android/marker#flatten_a_marker
The only requirement is that you reference the latest version of Google Play Services.
I'm also rewriting my app (Runbot) for the new API and had to figure out how to create custom markers representing milestones (like 1km, 2km, ...) and how to show or show not all of them depending on the zoom level.
I had a custom drawable that I used for the v1 API and what I do now to render the markers is about this (Position is a class of my own that holds the position and further information; all needed here is its LatLng property):
private void addMarker(Position p, MilestoneDrawable milestone) {
if (mMarkers.containsKey(p)) {
mMarkers.get(p).setVisible(true);
} else {
Marker m = mMap.addMarker(new MarkerOptions()
.position(p.latLng)
.icon(BitmapDescriptorFactory.fromBitmap(Util.drawableToBitmap(milestone)))
.anchor(0.5f, 1.0f) // bottom center
);
mMarkers.put(p, m);
}
}
Besides creating and adding the custom markers, what you see is that I keep the markers in a HashMap so I do not have to destroy and create them all the time. When it comes to zooming and deciding which ones to show, I first set all of the markers to invisible and than call addMarker() for those I want to be shown, and those which I already have in the HashMap I simply make visible again.
I hope this helps you a bit. I have a bit of mixed feelings towards the new API...
I had a similar problem where I had markers that needed to rotate. My solution was to have the object the marker represented be responsible for generating the marker. I have a few methods in the object that look like:
protected Marker getMarker(GoogleMap map) {
if (this.marker == null) {
marker = map.addMarker(new MarkerOptions().position(location).
icon(BitmapDescriptorFactory.fromBitmap(BusMarkerImageFactory.
getMarkerIcon(heading))));
}
return marker;
}
protected void updateMarker(GoogleMap map) {
if (marker != null) {
rotateIcon();
marker.setPosition(location);
} else {
getMarker(map);
}
private void rotateIcon() {
marker.setIcon(BitmapDescriptorFactory.
fromBitmap(BusMarkerImageFactory.getMarkerIcon(heading)));
}
This is from a system that draws buses with the markers pointing in the direction they are heading, so of course, your code will be different, but the concept is very similar. Instead of rebuilding the entire marker you're keeping a reference to it somewhere and then simply resetting the icon.
Of course, drawing all those bitmaps for minor changes is a drain on memory. I used a flyweight pattern in the (incorrectly named) BusMarkerImageFactory to keep 16 images for 16 possible heading ranges. It is a static class that simply takes in the heading and returns the image that I've mapped to that range.
can't you use addMarker(new MarkerOptions()) method ?
If you need a custom marker you can create an implementation of InfoWindowAdapter and use that implementation like mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
here is the documentation for InfoWindowAdapter
I try to offer 3 display modes to users of my app:
Traffic View (the standard view as on every printed map)
Satellite View (aerial) and
StreetView (3D, as done with the infamous Google Car)
I can set 'Standard' traffic view with
mapView.setSatellite(false);
mapView.setTraffic(true);
Satellite view with
mapView.setSatellite(true);
but
mapView.setStreetView(true);
doesn't do anything, even if I can get StreetView at the location checking with maps.google.com and a followup check for mapView.isStreetView() returns TRUE.
Can anyone help me out?
setStreetView(true) should load a tile set showing streets where StreetView data is available. It will not, however, actually display StreetView itself -- that is a separate application. You can launch StreetView, for devices that have it, for a given location by using a specific Intent structure. However, you cannot embed StreetView in your own app at this time.
I have an overlay which I want to declutter based on the range from the map center.
I want to detect a change in the current map center so that If a person is constantly moving the map around, panning to another area, I can declutter and repopulate data in the new area.
Is there a listener for this or am I going to have to create a thread to periodically check the map center?
I forget the name of it ..... you'll have to read the API documentation ..... but there are properties/methods of the MapActivity that define the boundries (in terms of lat / long) of the currently displayed map that you can use to determine what the center value would be. If the GPS is reporting the user is currently at XXX value, but they have panned the map in a direction that puts the calculated center YYYY away from where the GPS is reporting, then you can determine "how far away from center" the Map is now positioned. Use the Great Circle method, by the way, when doing the math.
I think something like this might work
When you first load the map get a projection and store the center GeoPoint of the middle of the view the map is being displayed on by using the MapView's Projection class
mapPosition = myMapView.getProjection().fromPixels(x,y)
Will return a GeoPoint related to x,y in this case x y needs to be he center of the MapView
Extend the MapView class
public myMapView extends Mapview { }
So you can override onDispatchDraw
In that method you can check if the zoom level has changed, if it has not then it's probably because the map is being panned, could be other reasons I suppose dependent on what you are doing but it's reasonable to think most redraws are pans if you exclude zooms
Compare the current projection GeoPoint of the center of the screen with the one you stored at startup. If it meets your distance critera perform your logic and update the mapPosition geopoint.
If I understand your question correctly something like that should work. Of course you could over ride other members of the extended class as well if you dont want to check on every redraw, the motion events could be used as well but you said you were having problems with those.
UPDATE:
You might be able to do this directly on MapView vs in a custom container but what I have done in the past is override dispatchTouchEvent on an extended container class that the mapview lives inside, in this case a Framelayout so
public class myFrameLayout extends FrameLayout {
Then inside of that I use something like this to track the state of the touch motions, I will reduce it to the minimum that should work, the "modes" are enums I created, where you would do
logic is when the user lifts the finger at the bottom of the case statement
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_UP: // Second Finger
case MotionEvent.ACTION_DOWN: // First finger
mode = GESTURE_MODE.PRE_DRAG;
break;
case MotionEvent.ACTION_MOVE:
if (GESTURE_MODE.PRE_DRAG == mode) // Pan
mode = GESTURE_MODE.DRAG;
else
{
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
mode = GESTURE_MODE.MULTI_TOUCH;
break;
case MotionEvent.ACTION_UP: // All fingers removed
if (GESTURE_MODE.DRAG == mode)
{
// DO YOUR PANNING MOVED FAR LOGIC HERE
}
mode = GESTURE_MODE.NONE;
break;
}
return super.dispatchTouchEvent(event);
}