I have an activity that displays a list on markers based on the state of a model.
Whenever the model's state is changed, the markers are refreshed to display the new location or display any new markers.
I want to test this behavior but GoogleMap does not provide a .getMarkers() method or similar to know which markers are shown on the map.
The question is, how can I test both the number of Markers and the LatLng or each marker.
keep an ArrayList of all plotted markers and iterate through to find the one you want?
or there is a 3rd party mapping library that you can call getMarkers, getPolygons etc..
Thats just an idea but you can store you marker (latlng, id, image, etc) on an ArrayList. Then when you create your marker, assign foreach the id and on click retrieve the id to get all information's from your Array.
Related
I have an requirement, in which Marker should be placed on clicking the Map within the city limit in Google Maps android.If user clicks on the map outside the city limit. Need to show an warning. I know it is possible to add marker on clicking on the map but how can i restrict it to city limit? I tried exploring the concept of GeoJson to add an layer above my Map.But I am not sure how this would help. Any suggestion appreciated. Thanks
Based on this link I could able to fetch polygons for a particular city. The values are stored to DB and fetched using an API. API returns lat lng boundary of a city, Using this I could able to draw an polygon in shape of City.
val polygon = googleMaps?.addPolygon(PolygonOptions()
.addAll(cityLimit)) // cityLimit LatLng list of City Boundary
polygon?.isClickable = false
polygon?.strokeWidth = 2f
Then onMapClick, I added the following condition
override fun onMapClick(latLng: LatLng?) {
if (!PolyUtil.containsLocation(latLng, cityLimit, false))
// Show error message "Unable to place marker outside city limit"
}
PolyUtil is an Class library of Google Maps sdk. This solved my problem. For more details check this blog
You should create a Geofence around the area you want the user to select. Then you can evaluate whether it is in the city boundaries.
Have a geofence like 10000m around the city,if the user clicks the map and find that it is not inside the geofence you cancel the request but if it is within the boundaries you create a marker
I want to show map only one city or country in my android app. How can I do it ?
I do not need to load map of all world
image 1
image 2
if you want to see only country or city you can use its latlng bound its focus on the particular city or country when user come first time here all country latlng bound https://gist.github.com/graydon/11198540
First, you have to be familiar with Google Map API (create an API key, import it to your project, etc.)
Then, get the LatLng of the city you want, and on the moveCamera method, pass to it a good zooming (it's a float). For exemple, when your widget is beeing launched, call something like : mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(yourCoords, 10f))
If you don't want / need to allow any user interaction with your map, just set the parameter "liteMode" to true inside your XML (or programatically), it will generate a bitmap of your desired location.
Bye.
Actually I wanted to get GPS co-ordinates of a particular place when user long presses that place on map by using HERE Maps Android SDK. Is it possible?
Yes it is possible. Use Map#getSelectedObjects() to retrieve the list of POIs that the user has touched. If the object is an instance of MapCartoMarker, the gps coordinate of the object is stored in MapCartoMarker.
I have an app in which I manually added some Markers to a google map. Then I saved the Markers to local storage. Now I want to re-run the app, load the set of markers and place them on the (now empty) map. I had assumed that there would be a method something like:
googleMap.addMarker(marker_I_loaded_from_memory), but I can't find it. Alternatively I thought there may be something like marker_I_loaded_from_memory.AddMyselfToMap(), but I can't find that either. Does either exist?
Edit: I am using maps API v 2
You cannot serialize Marker objects. They are connected with current view.
I suggest storing the relevant data in local DB. A table with latitude, longitude, title, etc. will do.
When recreating such Markers, use GoogleMap.addMarker(MarkerOptions), where MarkerOptions is constructed from the data in DB.
i'm developing an android application similar to Google places app.
I want a functionality to obtain the location of a place on google maps in my application. How do i achieve this?
This is the use case:
Using GPS my current location's lat and long will be passed using the notification service.
Then when i click on the button restaurant,the list of restaurants in that particular location will be displayed(all information is being retrieved from the server that i created using grails).
Then i select a restaurant's name from the list being displayed.and then in the user interface there is a button called "MAP" .
Upon click of the "MAP" button, the location of the restaurant i have chosen must be displayed on Google maps.
What's the thing that you can't do - displaying the restaurant on the map, or having just the name of the place, you wish to find it's address/coordinates on the map?
You can follow the official Android tutorial on the subject - Point 2 in this article: http://developer.android.com/resources/tutorials/views/… Probably this article will be useful as well: http://mobiforge.com/developing/story/using-google-maps-android
Part 1 and 2 guide you through the creation of a Map activity (you should start a new map activity when the user taps on MAP button) and how to add an overlay to the map. In the article the overlay is the android robot. The other articles uses a pushpin as an overlay. Overlay, on the other hand, is .. a picture that is displayed on the map. In your case - some pinpoint put on the coordinates of the restaurant. Once you've created the map activity, you can follow my second link and look for title "Adding Markers". It's very well explained.