Android Google Maps V2: Only Loads after zooming - android

I just started programming my first Android app. However, even after thouroughfully following the Google Tutorial, including (!) getting a valid API key, the Google Maps doesn't load from the beginning (that means I can only see the grid).
The tiles are (weird?) only loaded after I use finger gestures (+- does not work) to adjust the zoom to a (random?) level. I don't have any idea on what could be the matter...once the first tile got loaded, the app works as expected.
I already worked through StackOverflow, the problem with everybody else was they were using MapView (V1).
I'm using
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
however...

Related

Map generated in Cloud-based Maps Styling v3 does not work properly

After switching from maps v2 to v3 (due to Cloud-based Maps Styling) I get this result in Light Mode (as in the screenshot)
The map is as if covered by some black block (but this place is clickable -> maybe the phone is breaking something graphically)
If I change to Dark Mode on my phone it works fine
Map Fragment in Activity
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.libraries.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
map:mapId="#string/map_id"
android:layout_weight="1" />
Can something be done about it?

Google Maps works in debug not in apk

I added a map to a layout with a text view on top of it. In debug when I run the app on my phone the map comes up as expected. I pass my current longitude and latitude to the intent and the map centers on my location. The text view is visible and I can drop and pin and get the new coordinates.
I wanted to share the apk with someone so I first generated the file and emailed it to myself. After downloading and installing on my phone as a test I noticed the map no longer displays. There are no exceptions thrown. The text view is visible and the small 'Google' logo is in the bottom right, so the map there, but it is just a white screen. There is no map image. I tried to pinch thinking I am too zoomed in or out, but nothing changes.
Below is the layout of the activity. When I view it in design mode there is rendering problem. Part of the output from the rendering exception is below. the exception was 1025 lines long, which made it too long for a SO post. It was a lot of repeat, so i cut it down. I'm not sure if the two issues are related.
Is there anything wrong with my layout that would account for the problems? The phone shows that the app has the correct permissions for Location services.
I'm in Android Studio 1.4.0/ SDK 23
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:id="#+id/map" tools:context=".GarbageLocator"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="#layout/activity_garbage_locator" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/ItemName"
android:text="#string/hunt_item"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="32sp"/>
</RelativeLayout>
</FrameLayout>
java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.parsers.SecuritySupport.getSystemProperty(SecuritySupport.java:62)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:229)
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120)
at com.android.utils.XmlUtils.parseDocument(XmlUtils.java:432)
at com.android.utils.XmlUtils.parseDocumentSilently(XmlUtils.java:484)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.findCycles(LayoutlibCallbackImpl.java:397)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.getParser(LayoutlibCallbackImpl.java:315)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.getParser(LayoutlibCallbackImpl.java:306)
at android.content.res.BridgeResources.getLayout(BridgeResources.java:396)
at android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:135)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:879)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:831)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:197)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:879)
Part of the mystery solved. The rendering problem is because when I clicked on the design tab AS asked me to choose which layout I wanted to display in the fragment, so I chose the layout for the activity. AS then added the line 'tools:layout="#layout/activity_garbage_locator"' to the layout, which I guess caused a sort of circular reference. Ugh!
Also, after adding the new API key the map no longer works in either Debug or Release. Consistency in failure is progress, I guess. I added a new activity with a Google map and ran it as-is, that is to say, without any additional code, and it won't display a map either. I get the same thing: an off-white screen with the Google logo in the bottom left. Just as I would get if there was a map, but no map.
In my original activity with code to trap the longitude and latitude of a dropped pin, the map actually does work in that it returns a new longitude and latitude when I tap on the screen. It just doesn't show the stupid map!
Greg
It was an API issue, but I'm not really sure what was going on. I tried several different things after reading several different posts regarding this problem. I think what fixed it was hard coding the API key in the manifest, as one post suggested.
Original manifest entry
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
Change to
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIz_MY_ACTUAL_KEY" />

Android Studio Google Map V2 fragment rendering

I tried to write a test demo for Google Map V2 in Android Studio. I followed every step from Androidhive Google Map V2 or better I think I need.
I'm using the same layout_main.xml
<?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" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
but I'm getting always the same rendering problem:
Rendering Problems
A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
I have absolutely no idea what's the problem. Did I forget something?
I just need to add Google services in the build.gradle like
compile 'com.google.android.gms:play-services:4.4.52'
I copied the manifest from the demo and changed the API Key.
The accepted answer is not wrong but it does not help.
As Dan wrote, Android Studio (also Version 1.0) will not display the map.
Maps needs an API key and dynamic processed code, maybe some day we will have that but so far not.
I've a 5 minute solution for those who want to see their app properly in layout preview:
To properly develop I still needed something else than a blank background.
I added overlays and buttons on top of the map, I really needed to see the map while placing elements over it.
The solution is simple:
1. Make a screenshot of your app with the map running (Power + Volume Down)
2. Download the screenshot and use an image editor to remove the top and bottom UI elements, so you will end up with only the map itself as an image.
3. Import that image into android studio drawables
4. create a new layout, name it dummy_mapviewfragment, put only a linearlayout and an imageview in
5. make the imageview "fill" the parent, and set "src" to the cropped image you just imported
6. back to your layout, add this into your Mapview Fragment xml :
tools:layout="#layout/dummy_mapviewfragment"/>
That's it, now you will have a non-interactive mapview fragment which displays a real map.
Your app will look like it looks on your mobile phone.
If you made errors in your image cropping you can "fix" it by setting the image scale to "centerCrop" so it will properly stretch out.
Update: You can get a screenshot without need to crop directly from within Androidstudio! Makes it a bit more convenient ;)
Rendering Problems
A tag <fragment> allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
This is just the preview window telling you that it can't display a preview for the <Fragment.../> tag, because it doesn't know what kind of fragment you're going to put in it. You can safely ignore that message - your actual app will render the fragment fine when you run it (as long as you code it up correctly!).
Android Studio automatically offers a solution within the error description, which is adding the name of the fragment layout.
tools:layout="#layout/fragment_my"
Add a dummy layout "#android:layout/simple_gallery_item" as:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="317dp"
android:layout_height="385dp"
android:id="#+id/map"
tools:context="com.example.XYZ.googlemaps.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="#android:layout/simple_gallery_item"/>

Android Studio: xmlns:map not working

After doing a lot of research, and not finding anything... quick question, does anybody has an idea why Android Studio is not taking the Map tag? The code below is a fragment of the maps sample in the SDK. Already added google play services lib and support, but nothing.
It's showing the error
Unexpected namespace prefix "map" found for tag fragment.
Thanks a lot in advance!
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraZoom="10" />
I had the same problem once I've been moving the map fragment into FrameLayout (so I could add a button on top of the map).
I don't know what I've really done as I'm a noob in Android apps and XML, but it looks that I found the solution :-)
I tried to make the trick including the fragment from a separate file (using 'include' directive) and once I put the bare map fragment without any namespace definitions it proposed me 2 options:
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/tools"
I realized that maybe the 2nd one will work in the original file (although in original file Android Studio is not proposing it, but only the 1st one instead).
Conclusion:
Just change this line:
xmlns:map="http://schemas.android.com/apk/res-auto"
with this:
xmlns:map="http://schemas.android.com/tools"
AS I MENTIONED - I'M A NOOB AND MAYBE MY SOLUTION GOT SOME SIDE EFFECTS SO PLEASE LET ME KNOW IF SO (although everything seemed to be working fine by so far...).
That's my working map layout with a button on the top and no errors:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/tools"
tools:context="com.maverickrider.myapp.inviteActivity.MapsActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/purpura_E51B4A">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
map:cameraTargetLat="51.513259"
map:cameraTargetLng="-0.129147"
map:cameraTilt="30"
map:cameraZoom="13"
/>
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="cokolwiek"
android:text="Baton z dupy"
android:layout_alignParentBottom="true"
/>
</FrameLayout >
I had this problem as well. I did Project/Clean and the error went away and it works fine now. This assumes that the map namespace is properly defined above where it's being used.
I'm running 0.5.8 and the XML viewer is underlining the attrs with map: - however the app is building fine. YMMMV.

fast map loading issue with multiple markers in android?

I have problem in loading map with multiple marker in samsung epic.map will display after some time.pls give me the solution.
Thanks.
Google maps are dynamically loaded from internet. This is where the delay comes from. Check you internet connection.
If you are using map only for marker display purpose use lite map special feature by google map Lite Mode
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraZoom="13"
map:mapType="normal"
map:liteMode="true"/>
map:liteMode="true" it will make map in lite mode with some limitation
AND
For too many marker go with clustering of marker google link
clustering will increase readability of map
BEFORE CLUSTER
AFTER CLUSTER

Categories

Resources