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.
Related
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 making an app which downloads LatLngs from firebase and shows them as markers in google maps API, users can add new LatLngs.
In my database I also have the pricepoint and types of markers. In the main screen the user can choose what types of marker he wants to see on the map.
So my application does something like this:
locations.orderByChild(pricepoint).equalTo(choosenPricepoint);
and then I check programmatically if types match those chosen by the user
int type = Integer.parseInt(locations.child("restaurantType").getValue().toString();
if(type == funCode|| type == runingCode|| type == sportsCode
{
mMap.addMarker(new MarkerOptions().position(snapshot.getLatlng);
}
And it works fine with 250 records, but I'm expecting over 10,000 of them in my database so I am worried that it will be too slow.
I don't know if showing markers only where user's maps camera is and deleting other will be faster. What do you suggest?
You can use GeoFire , a firebase library that uses GeoHashes to merge lat+lon into a single property.That way you can do the distance filtering directly on the database.
You should have 2 entries in firebase database,one for setting your object location and one for setting your object with its fields.
As you can see they have the same id.So first you are queriing for nearby object by GeoFire in geo_data entry,and you will get the ids of the object which are nearby,then you can retreive object with its properties directly from database using the ids in my case in user_data entry
So, I have an Activity with a Fragment that stores input latitude and longitude, and another Activity with a Fragment containing a map. How can I store and transfer the latitude and longitude from one Activity to another? I have an inkling this would need an SQLite database, but I'm unfamiliar with that. Can someone please provide a suggestion/example of how I'd do that? I know how to create markers and write to files but that would be cumbersome and take up unnecessary memory.
I'm using Graphhopper as a routing service for my Android project and I want to know how can I extract street data (as a polygon) from *.osm.pbf format?
Later I want to use that data so that I could detect if user is within boundaries of that street.
Edit:
I've used Osmosis as it was referenced in this answer (selecting highways) but when I try to investigate xml after extraction I still don't understand how can I get a particular street since there still are some other objects left (like houses, bus stops).
Well I guess here are a few misunderstandings, so I go trough your wishes step by step:
OSM street data
What grasshopper uses aren't street polygones (closed shapes) nor simple street lineshapes. It processes pure OSM data and creates a so called routing-graph presentation. Here are a few informations about the import process itself: https://github.com/graphhopper/graphhopper/wiki/World-Wide-Road-Network
User position on road
This is called reverse geocoding and has different requirements on the indexing structures and models. OSM offers Nominatim as a solution to query like (lat, lon) -> OSM object. Your idea with a spatial buffer is even possible but creates a lot of overhead (here: memory) to preprocess your roadnetwork or doing it on demand for a particular area.
Street data is stored in GraphHopper. You could traverse the full graph e.g. via extending XFirstSearch and then do on checkAdjacent:
boolean checkAdjacent( EdgeIterator iter ) {
PointList pl = iter.fetchGeometry(3);
String name = iter.getName();
}
If you want to get an edge from a location for the "fence-use-case" you can have a look into LocationIndexTree.
Some clarifications:
Routing graphs usually don't contain spatial informations
The routing graph itself does not need this data but still we need this data to display the route etc.
Is there a way then to add weight to a node during the calculation
As explained on the mailing list.
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.