I populate my google maps with number of Markers based on my server data.
MY server data contains ProfilePic , Name , Designation , & lat long etc...
When I click on my Marker I open BottomSheet that display the details like ProfilePic , Name , Designation . just like google map does
I don't know how do I get ProfilePic and other data on click of my marker .
I am very familiar to Recyclerview adapter concept ,
How do I apply this concept to my marker ?
You can set custom adapters of infowindow for marker in google map.. check this example--http://androidfreakers.blogspot.in/2013/08/display-custom-info-window-with.html
Solution 1-> You can use HashMap for mapping of markers and your server data list.
Solution 2-> You can append the id or position to marker title with token(comma, semicolon...) and then onClick marker you can break them for further mapping to your server data list.
In this case you also need to override customInfoWindow.
Example to follow:-
http://devlearning.blogspot.in/2014/05/android-custom-info-window-with.html
Hope this may helpful to you
Thanks,
Bhuvnesh
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.
I am planning to get the marker ID and want to show some information based on marker id. I am using the following code to get marker id:
Log.d("marker", marker.getId());
I have a seperate line where I want to associate marker id with other tasks, however, for some reason it doesn't show any values/execute that section.
if (marker.getId().toString() == "m1") { .... }
any help would be highly appreciated
that is not how you equate a string in java.
marker.getId().equals("m1") is what you want since getId is already a String you dont need to do toString()
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.
Iam building sample android app . Initially am displaying list with some cities.by clicking on any one of the city it will display map regarding to that city.
now am suffering with how to connect selected city from list with googlemap.any idea please let me know.
You simply make the list of city objects. Each object will contain the name of the city and the location (latitude, longitude). When you click an item, go to a map activity passing the location in the Intent object. In the map activity you'll parse the location and tell the map to go to that point.
Firstly, U have, for example database(or local data structure in your list activity) with cities and corresponding coordinates. Then, in onListItemClick() you create new intent and insert to it's extras necessary data (title, coordinates or primary key of the row in db table). Start new activity extended MapActivity with this intent, take mMapController = mMapView.getController(); and animate to mMapController.animateTo(new GeoPoint((int)yourLatitudeE6,(int)yourLongitudeE6)), where yourLatitudeE6 and yourLongitudeE6 - extras from intent
I think you should have lat and long of city .So you can send that lat and long to mapview through bundle and populate map of that city. In this link you can get complete tutorial for mapview . http://www.vogella.com/articles/AndroidGoogleMaps/article.html