before I posted my problem here, I have been done some researches but none of them helps. The weird part is that it worked last night and I believed nothing has been changed at all. However, I can't make it work now because the findViewByID returns null for no reason
public class ShowInMap extends MapActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
MapView mapView = (MapView) this.findViewById(R.id.mapview);
if(mapView == null)
{
Log.i("test", "test");
}
}
}
and this is my mapview xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Map Key"
/>
I am thinking maybe my debug key has expired but if that was the case, I should have gotten some errors from Eclipse saying my key is expired or something? Shouldn't I? It is a bit frustrating, any comment would be appreciated. Thank you
Try cleaning the build. This happens to me every-now-and-then. Usually if I just clean the build and then to a complete rebuild, things seem to work.
Related
I have successfully been using osmdroid-android-4.1.jar for a while to display OSM map tiles in my app.
Now, since yesterday, I don't get any tiles at all displayed. When I connect my phone to the PC I see the 403 forbidden response in the log. I built the app on an Ubuntu machine using Android Studio. I haven't got a good understanding of .aar file yet, could it be that the 4.1jar is now outdated and not setting the correct user-agent?
I know Mapquest isn't supported now but I'm using Mapnik tiles
All information gratefully received
Update
I've just tried an old Eclipse based project on my Windows PC. That uses 4.1 jar and I ran it in an emulator. I see the same 403 response and no map tiles. The tile source is
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
I know this project used to work. The cache tiles show Ok but if I move the map - no tiles.
The entire code is
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.DEFAULT_TILE_SOURCE);
mMapView.setBuiltInZoomControls(true);
mMapController = (MapController) mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
mMapController.setCenter(gPt);
}
}
/* HAVE THIS AS YOUR osm_main.xml
---------------------------------------------------------- XML START
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</LinearLayout>
---------------------------------------------------------- XML END
Include slf4j-android-1.5.8.jar and osmdroid-android-4.1.jar in the build path
(Google search for where to get them from)
*/
I have posted this code before as an answer and as an example of the smallest working osmdroid sample - well it isn't a working example now!
We had the same issue today.
In build.gradle we changed this:
compile files('libs/osmdroid-android-4.2.jar')
to:
compile 'org.osmdroid:osmdroid-android:5.1#aar'
And added this:
OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
before loading the map.
You can read more about the issue here:
https://github.com/osmdroid/osmdroid/issues/366.
Hope this helps you too!
I'm currently working on Android and have started with Google Maps V2 API.
As I have finished going through all their setup guide the map worked and I was able to see the continents. Only problem is that when I zoom in, the map stays the same I just get less pixels untill eventually I get gray squares - as if it has loaded the map but not entirely. I'd been looking around for someone with a problem like mine and couldn't find any.
Any assistance will be appreciated.
My code:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
public class myMapActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
}
More information:
I had added:
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
and gotten gray squares without map at all. hope it helps identify the problem Thank you in advance.
As recommended I had uninstalled which probably removed previous save of the map.
After reinstalling the app works fine.
I'm struggling with a memory leak issue at Google Maps Android API v2. The heap usage increases by about 85KB every time my view becomes visible again after:
Phone screen turns off (eg after pressing the power button).
The user exits the app pressing the Home button.
The app eventually crashes with an OutOfMemory exception. The leak does NOT occur on screen rotate, or when exiting by "back" button. Any ideas about a workaround or the reason behind this problem?
My code:
public class LeakActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leak);
}
}
and the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
This might be related to this open issue in the Maps API:
Issue 4766 - Bug: Android Maps API v2 leaks huge amounts of memory
Use DDMS' "Dump HPROF" tool to dump a hprof file, convert it with hprof-conv and use MAT to examine the leak. If it's in Google Maps API, please post an apk (or better simple test code) to the open issue and include the hprof file.
If it is the same bug I am experiencing, it might only happen on Android 2.x, please check that too.
I tried to use System.gc() and map.clear() before the map is initialized.
#Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
System.gc();
getMap().clear();
setupmap();
}
}
#Override
public void onLowMemory() {
super.onLowMemory();
System.gc();
}
public class Map extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
MapView mapView = (MapView) findViewById(R.id.myMapView1);
mapView.getController().animateTo(srcGeoPoint);
mapView.getController().setZoom(15);
}
the map.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="#+id/myMapView1"
android:layout_width="fill_parent"
android:layout_x="0px"
android:enabled="true"
android:clickable="true"
android:apiKey="Obtained Key here" android:layout_y="105px" android:layout_height="fill_parent">
</com.google.android.maps.MapView>
</LinearLayout>
I check the log there's only one red mark, Failed to find provider info for com.google.settings. everything else seems to be fine. I am wondering why the map is empty looking?
The MapView is empty when your Maps API key is expired or not matching with your debug signature key.
Try to generate a new one.
Inside every MapActivity, the isRouteDisplayed() method is required,
so override this method:
#Override protected boolean isRouteDisplayed() {
return false; }
This method is required for some accounting from the Maps service to
see if you're currently displaying any route information. In this
case, you're not, so return false.
source: http://developer.android.com/resources/tutorials/views/hello-mapview.html
Additional the android:layout_x="0px looks a little bit dodgy to me. I think it's only used in AbsoluteLayouts so deleting it should not harm.
Please check logs whether you are not getting "unable to authenticate error from google server". If yes there is issue with map key.
Map key should be generate on same system where you are running application.
Also check whether you have google play account signed and location setting is enabled.
please check here for more details:
https://developers.google.com/maps/documentation/android/start
Since few days my application does not show maps anymore.
To make sure my code is right, I decided to test the MAPS Tutorials
application found in developer.android.com here.
The maps on the tutorial does not show either.
I just see the usual little grids of the Mapview.
When I tap it I have the normal response telling me the corresponding Geocodes.
Any idea why ??
The code of the tutorial is this one:
public class MapsActivity extends MapActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
MapView mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="my key"
/>
Generally if your map only shows a grid and no tiles you are mixing a release apk with a debug api key or vice-versa.