Android SDK mapView. Get map zoom level/position - android

I have the map working on android and am able to populate it with overlays.
But the overlay ability is only so good. If I add too many overlays and refresh too often, I can create an app that is very processor-hard (useless).
What I want to do is only load the overlays that are within the zoom level of the map.
How to I get at what level the map is zoomed using Google APIS, overlays, itemized, and geopoints?
Thanks,

You can use the getZoomLevel and getMapCenter methods on MapView. You might also read through the MapView class documentation.

You can directly get that from class without any method.
map.getCameraPosition().zoom

Related

MapView within ExpandableListView

In my ExpandableListView I need to add Google Map on each item.
I tried with putting Map on each item but its giving me inflate exception. And its is also stated that an MapActivity can contain only one MapView.
Is there any other idea to achieve this.
For refrence you can see here.
Your comments regarding MapActivity indicate that you are using Maps V1, which is deprecated. Maps V2 does not require a MapActivity and can have multiple maps.
That being said, your proposed implementation is unlikely to work well, as putting scrollable things in scrollable things can be problematic. It also is rather unrealisitc IMHO -- whoever came up with that design has never used an actual smartphone, as there's no point in having an interactive map that small (again, IMHO).
Consider using static maps (there's a Google API for that somewhere) for inside the ExpandableListView, where a tap on the map brings up the full map, either in your app or in the standard Maps app.
I recommend to not use static map (as for example it's not possible to zoom to particular bounds with newLatLngBounds or add a circle in particular lat/lon).
I recommend to use map fragment in lite mode:
In addition, there is also a new ‘lite mode’ map option, ideal for situations where you want to provide a number of smaller maps, or a map that is so small that meaningful interaction is impractical, such as a thumbnail in a list. A lite mode map is a bitmap image of a map at a specified location and zoom level.
Map fragment can be nested in the list.

Should I use MapView or MapFragment

I am not sure whether I should be using MapView or stick to using a MapFragment. My application is an app that finds the nearest set of places that are closest to you. I want to be able to add locations, display details of a marker when I press a marker and when the user moves along the map I want to be able to get the coordinates of the center of the map and display the nearest locations within a defined radius. Would I be at a disadvantage if I continue to use MapFragments or should I switch over to MapView while I still have the chance?
First of all, soon the MapView and Google Maps API V1 will stop being supported and won't receive any new updates. And soon all the support will go away.
Secondly, MapFragment may be a little bit less flexible right now, but the map presented, manipulated a looks much better. And I guess that it's functionality will improve with time.
So I would definitely continue to use MapFragments.
UPDATE:
As #Brian White pointed out in the comments, today there is a MapView in Google API V2, and you should use it when you want to embed a map in a fragment. That way you will avoid cascading fragments when you don't have to.
MapFragment
Use it if you want to add a map into Activity class (not fragment
because it will create a nested fragment and it´s a mess).
Use SupportMapFragment if you want to support just android versions
lower than v12.
MapView
Use it if you are going to add a map into a fragment. (you need to
update each lifecicle to MapView).

Map overlays in android

I would like to ask about how can I add different overlays to my android application?
as I already have one overlay class that extends Overlay and it draws polylines according to some points in a KML file.
and now I would like to create another overlay that adds a pin in the user's location using GPS, so I don't know how this could be done.
please anyone knows how to help me ?
thank you in advance.
You can have multiple overlays on top of one map.
Just create the second layer as an ItemizedOverlay, and add it to the map:
myMapView.getOverlays().add(myItemizedOverlay);
To learn how to add markers to an ItemizedOverlay, see http://android-coding.blogspot.com/2011/06/using-itemizedoverlay-to-add-marker-on.html.
To add a pin to the user's location use MyLocationOverlay it's in the google maps API see this link
Android GoogleMaps API Documentation may also help.

How do I drop spots on Google Map in an Android app?

I'm developing an Android application where I want to pin out certain spots/addresses on a google map. I have managed to add point to a mapView using OverlayItem and a Drawable. That works great.
But I have installed an application where the pins/spots are added asynchronously, and it looks like they are dropped from the top of the screen on to the map. Looks really nice.
I think I can manage to code the async functionality using threads, but I have no idea how to implement the "falling" feature... Does anyone have a clue??
That would seem difficult, unless the map were stationary.
If the map won't be panning/zooming, you could do the "falling" via a TranslateAnimation, applied to an ImageView that floats above the map (e.g., later child in the RelativeLayout that holds the MapView). When the animation completes, you'd make the ImageView be View.GONE, and you'd add the actual marker to the ItemizedOverlay.
Here is a sample project showing how to do drag-and-drop of an OverlayItem using a similar core concept.

Adding markers to a Google map on Android

I've got a place I want to add on my map at a particular lat / lng. I'd like to display that on my map when the activity starts. How would I do this?
Thanks.
This Google/Android tutorial should provide exactly the information you need.
Basically you create an custom ItemizedOverlay, grab a list of overlays from the MapView (getOverlays), create some GeoPoints and your set.
The Google Maps library documentation is a great reference for map related questions.

Categories

Resources