Android GoogleMap V2 on zoom map doesn't get sharpen - android

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.

Related

I need to show World map with GroundOverlay on map with animation

I need to show world map on my application.
I tried to use MapView and set liteMode= true and zoomLevel=1 but its not working as i need. Also groundOverlay not supported in liteMode and i need to show multiple groundOverlay on WorldMap.
can anyone know about it?
Please refere below link i need to show full world map like this.
https://upload.wikimedia.org/wikipedia/commons/b/b0/World_location_map_%28equirectangular_180%29.svg
Below code i done :
<com.google.android.gms.maps.MapView
android:id="#id/mapView"
android:layout_width="match_parent"
android:layout_height="#dimen/dp_180"
map:liteMode="true"
map:cameraZoom="1"
map:mapType="normal"
/>
In my Java Class
#Override
public void onMapReady(GoogleMap googleMap) {
if (googleMap != null) {
this.googleMap = googleMap;
this.googleMap.getUiSettings().setCompassEnabled(false);
this.googleMap.getUiSettings().setAllGesturesEnabled(false);
this.googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
this.googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.style_json));
this.googleMap.getUiSettings().setMapToolbarEnabled(false);
this.googleMap.getUiSettings().setCompassEnabled(false);
this.googleMap.getUiSettings().setScrollGesturesEnabled(false);
}
In this is added zoomLevel=1 but in google map its not showing world map as like above image link i shared.
CameraPosition cameraPosition = new CameraPosition.Builder().
target(YourLocationPoint).
tilt(60).
zoom(15).
bearing(0).
build();
myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
You can use tilt and bearing for achieving same Doc
Set style for Google map , in onMapReady of your activity.
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getActivity(), R.raw.customized_map_style));
you need to download the style. please go through below link
https://developers.google.com/maps/documentation/android-sdk/styling
update the styles as you wish.

OSMdroid Cannot get current location in android studio

Firstly I am new to OSMdroid.
I know there is other similar questions on this topic but there are no recent questions and the answers to the older questions don't work on my code...
I can't get the current location using OSMDroid.
I have used the simple tutorial given on github and the suggestions given in previous questions.
I have the latest version of OSMDroid but when I try to add a tag for the current location, nothing comes up.
I don't even get errors, the map just displays with no marker for the current location. Help! Here is my code.
Any help would be greatly appreciated as it is very annoying!
Java Class
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
//important! set your user agent to prevent getting banned from the osm servers
Configuration.getInstance().load(ctx,
PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
IMapController mapController = mMapView.getController();
mapController.setZoom(9);
GeoPoint startPoint = new GeoPoint(52.1237453, 6.9293683);
mapController.setCenter(startPoint);
this.mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(ctx),mMapView);
this.mLocationOverlay.enableMyLocation();
mMapView.getOverlays().add(this.mLocationOverlay);
XML code
<?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">
<org.osmdroid.views.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik" />
</LinearLayout>
Two possible reasons.
1) Your manifest is missing permissions for ACCESS_FINE_LOCATION
2) If the target SDK is 23 or newer, you have to ask for user level GPS permissions before creating the GpsMyLocationProvider
There are examples of both in the osmdroid sample application's source code, located here:
https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/intro/PermissionsFragment.java#L94
and here:
https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/AndroidManifest.xml#L24

osmdroid MapTileDownloader now showing 403 forbidden as HTTP response

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!

Memory leak for Android Google Maps API v2

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();
}

The google map looks empty inside the simulator

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

Categories

Resources