I currently have a Google Map Activity which is apparently working well but doesn't show the map (this sounds stupid!)
Here is a picture that will make you understand better my problem:
I already confirmed my apiKey, checked the tutorial over and over and even the manifest seems not be missing anything.
I get only this on adb:
276 MapActivity W Recycling dispatcher
com.google.googlenav.datarequest.DataRequestDispatcher#43ea39b0
276 MapActivity V Recycling map object.
51 GpsLocationProvider D setMinTime 1000
276 MapActivity I Handling network change notification:CONNECTED
276 MapActivity E Couldn't get connection factory client
Does anyone have a clue about what may be causing this?
Thanks.
Are you running the app signed with your key from your key store, or the debug key (clicking run in eclipse will sign the apk with a debug key and install it on the device - be it the emulator or a physical device).
If you have a map key (apikey), the keystore will have two different hash codes depending on whether you use the debug key, or your key - so you need two different map keys depending how you are running the app (the debug one will only be needed when you are developing the app).
Take a look at the debug section: http://code.google.com/android/add-ons/google-apis/mapkey.html#getdebugfingerprint
IF you are using setSatellite(boolean) and setStreetView(boolean) then you can face such situations. This is a BUG in Map View. Use only one of these two methods or you can try with some combinations of these two. Some times, use of only one of them solves the problem sometimes, you need to use a combination of both...like I did in my particular case..
streetView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mapView.invalidate();
mapView.setSatellite(false);
//mapView.setStreetView(true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("satelliteView", false);
}
});
satelliteView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mapView.invalidate();
mapView.setStreetView(false);
mapView.setSatellite(true);
}
});
Are you sure that you are properly setting the API key for the MapActivity/View?. Can you post your layout xml and source code?
Make sure to follow the steps from this tutorial: http://code.google.com/android/add-ons/google-apis/maps-overview.html
It will also show a map like that if it you send it a fake lat/lon pair where there is no useful map data, eg. "geo fix 0.0 0.0" (North Pole)
Try "geo fix -0.1 51.5" (over South London) where there is Google map data.
The problem was that the coordinate was wrong and that way the map was so zoomed that it wasn't able to show anything.
I zoomed out and I there was the map; so it was a coordinate problem and not a key/map activity problem.
For those who can't zoom out in these cases add this to your code
mapView.setBuiltInZoomControls(true);
and in the layout
android:clickable="true"
Related
I am working with Google Maps Android API V2.
When my map fragment is loaded it shows my location automatically (with the blue dot). Why does this happen? Is my location history affecting or is the default working mode?
Does this code cause it?:
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
googleMap.setOnMyLocationChangeListener(null);
}
});
I have commented this piece of code but the map is still showing the blue dot.
If this is not happening because of the history, would this piece of code be enough to get user location or do I need to use LocationManager class as described in other questions?
Try to use
googleMap.setMyLocationEnabled(true/false);
to control showing your location on map. I think it is enough to turn the setting on to make your location work with Google Maps, without need to use LocationManager etc.
I'm using Google Maps v2 in an Android application that I'm writing. After creating the map and adding all the markers to it, I make all the markers draggable by using marker.setDraggable(true); for each marker on the map.
If I run the code like this, the markers are indeed draggable. However, I'd like to change the icon or color of the marker while it's being dragged, so I set up an OnMarkerDragListener, like so:
map.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
#Override
public void onMarkerDragStart(Marker marker) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
}
#Override
public void onMarkerDrag(Marker marker) {
}
#Override
public void onMarkerDragEnd(Marker marker) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker());
}
});
After adding in that block of code, though, the markers are no longer draggable. The color successfully changes in both the onMarkerDragStart and onMarkerDragEnd methods, but that's it. Can anyone explain what I'm doing wrong here, and why the markers aren't getting dragged ?
i would say that the problem comes from changing the icon rather than from settings the listener.
Please note that Marker.setIcon is not a function that is available in all the versions of the GoogleMaps V2 API. This means that probably it is not available in the library you have, or in the version of the play services installed in the device in which you are trying your app, and that could be causing any kind of malfunction.
As you can read here that function was added in May 2013. Please try updating everything, the google-play-services_lib, and the play services installed in the device.
If this happen to fix it, then you can try to change the icon only depending on the version installed on the mobile.
i working with osmdroid and i want to change the TileSource at runtime (via menu entry). For example i can change between OSM TileSource and GoogleTileSource.
Problem: Everything works fine, but when i change the TileSource while the mapview is loading a Tile in the background, it changes the TileSource but one or two tiles are from the TileSource befor. So i see a mixed MapView with OSMTiles and one or two GoogleTiles.
The tileCache is cleared everytime after changing the TileSource. But the loading tile in the background isnt in the cache at this moment, so he put this tile to the cache, after clearing it.
Any Idea to workaround this issue?? It is all based on osmdroid, i only work with setTileSource(ITileSource)
Thanks and Greetz
Looks like a proper bug to me. I think you should report it as such. I can not see anything like it in the issues list. It looks like the bad tile even gets into the wrong cache on the sd card which is bad as it will be there for a while.
If you are using osmdroid3.0.6.jar (and I think you are, as I can reproduce this bug if I build with 3.0.6). I think it's another manifestation of the issue I raised osmdroid-android-3.0.6.jar, tile loading slow or fails. This bug has been accepted by the authors.
I suggest you go back to using the 3.0.5 jar. I don't get any problems with that. (I'm still puzzled as to how you get to use Google tiles with Osmdroid)
I think we all think it is a bug (or maybe it is not wanted to switch the TileSource at runtime).
I created a little Workarround. It works but it is not realy nice or recommended.
I created a new mapView and extend the osm MapView. Than create a RequestCompleteHandler, so i can see when a tile is finish loading and saved into the cache. Than i count every cached tile and only allow to switch the tileSource after 15 tiles are loaded. (at the start of the app osmdroid will load 15 tiles and only load some more after moving the map)
class RequestCompleteHandler extends SimpleInvalidationHandler{
private LbsMapView mMapView;
public RequestCompleteHandler(LbsMapView pView) {
super(pView);
mMapView = pView;
}
#Override
public void dispatchMessage(Message msg) {
super.dispatchMessage(msg);
Log.d("DEBUG", "HANDLER HAT GERUFEN! BACKE BACKE KUCHEN!! " + tileCount);
tileCount++;
}
}
then override the setTileSource method:
#Override
public void setTileSource(ITileSource aTileSource) {
if(tileCount <= 15){
Toast.makeText(mContext, "Jetz eher nich", Toast.LENGTH_SHORT).show();
} else {
tileCount = 0;
super.setTileSource(aTileSource);
}
}
and you need to set and initialise the Handler in the constructor:
mHandler = new RequestCompleteHandler(this);
getTileProvider().setTileRequestCompleteHandler(mHandler);
done. Now you can switch the tileSource only when it allready loads 15 tiles.
A little Problem: if the source are not working and do not load any tile you are in problems :D
But important: it is not recommended, its realy ugly code
This is very, very strange. I've never seen anything like it. At the time I am took this screenshot, I'm not loading any overlays. First, I thought it was my internet connection where it couldn't download the tile information; but we have many users reporting the same issue who downloaded from the market. This just started happening like a week ago. Not sure why though. Anyone have a clue? Thanks!
Ok. After starting from a clean project I found these two lines of code that was the culprit.
mapView.setSatellite(true);
mapView.setStreetView(true);
They appeared back to back of each other and I looked back at the very beginning of development and they were there and it worked just fine. Apparently, this is a BUG in the MapView as I'm guessing it tries to show both SateliteView and StreetView at the same time. One would think that the latter would override the former; but I guess not.
So, the question I have is, why this all of the sudden surfaced just within the last week or so. My guess is that the Maps Application was last updated in the market on Sept 8th and maybe a day or so after updating from the market, this issue started to resurface.
As a test, can someone just add these two lines to their code and confirm you get the same behavior?
I had only setStreetView(true) and getting those annoying grey boxes. I played around with both lines with no luck. Solved it by removing both setStreeView and setSatellite from my code, goes to streetview by default.
I had the same problem with my app that uses google maps library... Because i have in my setting option where user can change view of the map to Satelite or Street, i dont use setStreetView(true) at all...just mapView.setSatelite(true or false)...
preferences = PreferenceManager.getDefaultSharedPreferences(this);
pogled = preferences.getString("list", "Street");
if(pogled.equalsIgnoreCase("Street")){
mapView.setSatellite(false);
//mapView.setStreetView(true);
}else if (pogled.equalsIgnoreCase("Satelite")) {
mapView.setSatellite(true);
}
As you can see i had mapView.setStreetView(true) but that gave me a headache... :D I hope this will help you...
I removed setStreetview(true) from my code and now its working fine i was saw this issue occured in last 2 weeks , nyway we finally solved the issue thats great
Street view is always considered as the default option.
The problem arises when we use both setStreetView(true) and setSatellite(true) at the same time. Problem will be solved like this
if(mapView.isSatellite()){
mapView.setSatellite(false);
}else{
mapView.setStreetView(false);
mapView.setSatellite(true);
}
I hope that will help
private void setUpMapTypeScreen() {
if (mapType.equalsIgnoreCase("Satellite")) {
mapView.setSatellite(true);
// mapView.setStreetView(false);
} else if (mapType.equalsIgnoreCase("StreetView")) {
mapView.setSatellite(false);
// mapView.setStreetView(true);
}
mapView.invalidate();
}
mapType is a user defined string variable. Not false the previous view type when switching to view types. that the error we made, only set the view type you required.
I had the same problem, I took out my mapController, and it fixed it. The only other thing I did different was put the mapview in a linearlayout with a textview (it used to just be a mapview only) and I played around with the mapcontroller, commenting it out.
Since those are the only two things I changed, I'm pretty sure your problem lies in there as well.
I was having the same problem and the common advice that I have got is to not use setStreeView(true) and setSatellite(true) together. Some have even suggested not to use setStreetView(true) altogether. But my code was working okay before. I had to reinstall my machine and therefore installed android SDK and other components afresh after which this started happening. So my guess is that this is an issue with some specific version But I have found out that this problem occurs specific revision of 2.2 - in my case Android SDK Platform 2.2, revision 3. I have tried running same code on 2.3 and it works correctly i.e no grey boxes.
Besides removing mapController.setStreetView(true), there is also another thing that should be added to the layout XML..
xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapa"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="YOUR API KEY"
android:clickable="true"></com.google.android.maps.MapView>
Note the xml namespace after com.google.android.maps.MapView. After adding the namespace, the cross tiles disappeared. Don't know if it's a bug or the namespace is necessary in order for the api render the map correctly. Either way, it worked.
Im writing a small webapp based on the idea of openspot for training proposal.
When I open the map with my desktop pc everything is fine, but when I open it with my HTC Desire and add a marker the map hangs.
You can find a demo here (in german)
http://park-a-lot.de
Just go to "eintragen" and set a marker.
Then go hack and click on "parkplatze".
You'll see the issue.
Its ok that the toolbar at the top hides when you move the map, because of a jqtouch bug with Google maps.
Thank you in advance.
This solution may help. I know it works great in the ipod safari browser and Opera on an HTC Android phone.
http://nickjohnson.com/b/google-maps-v3-how-to-quickly-add-many-markers
Having lots of markers on the map does really slow it down on android. One thing you can try is to only show the relevant markers, i.e. those that are in the bounds of the map. In my case this made the map much less sluggish:
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = map.getBounds();
for (id in stations) {
var marker = stations[id].marker;
var isVisible = marker.getVisible();
var shouldBeVisible = bounds.contains(stations[id].latLng);
if (isVisible != shouldBeVisible) {
marker.setVisible(shouldBeVisible);
}
}
});