Google Maps: Saving markers to text file/other? - java

I'm making an application where the user can create a set of markers and then have the option to export them in some sort of file, so that not only can the map (with the markers) can be saved and reopened, other people using the app can import this file into their application.
At the moment, every time I create a marker, I add the marker object to an arrayList. Here is the code for that:
List<Marker> markers = new ArrayList<Marker>();
Marker m = mMap.addMarker(new MarkerOptions()
.position(new LatLng(lati, longi))
.title(title)
.snippet(snippet)
.draggable(true));
markers.add(m);
This seems to work reasonably well; I am able to get the properties of each marker through methods such as getTitle() or getSnippet() etc.
However, everytime the activity is destroyed, this contents of this arrayList disappears as well, thus I feel as though I need to save this information is some file. Here are my questions:
Is saving objects in a text file a good idea? Or should I save strings and integers (only the info i need, rather than the whole marker) and use something else instead of textfiles (sharedprefences maybe?)?
How would I be able to do this? Examples for the export and import functions of all the markers would be really helpful.
Whenever I rotate the device, the activity is destroyed, thus all the info is gone. Will i have to export and import everytime this happens?
Any help or insight to any of these questions would help a lot :)

you can use content provider for sharing data between app.
see this https://developer.android.com/guide/topics/providers/content-provider-creating.html
for avoiding to refresh after screen rotation add this line to your manifest file
android:configChanges="keyboardHidden|orientation|screenSize"

Related

Google Map Big Markers inaccuracy on tap

I am facing a problem while i am developing an application Using Google maps SDK.
I am creating dynamically some markers on the map, but these markers are quite big (using custom marker image and label above them).
But when i try to tap on a specific marker many times it selects the very next to it.
The accuracy of the click is not perfect and more over some times i need to click twice in order to get the click event get fired.
Making a google search i found that there are some issues with google maps sdk markers.
Is the issue being caused because of the size of the markers?
You can you marker options like this.
MarkerOptions lMarkerOpt = new MarkerOptions()
.title("Title")
.draggable(true)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.position(YourLatLng)
.snippet("Title");
It will use default marker with whatever color you want.

How to clear location marker in Google Map

I am creating a map application using GoogleMap. I have a problem while moving a CustomMarker from first to second location with help of location change listener. CustomMarker gets duplicated because its maintaining the older position as well while updating to new location. Please refer the below image.
Duplication of single custom marker
Why won't you just clear() GoogleMap in order to remove old marker?
https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#clear()

How to add and retrieve places on google map

i am creating a app which offers a service for place to register and store general details and their location then I'd like to retrieve these places locations on the Android app ,based on the user's location, So that when a app user open the app, the registered place near that user in a 5 mile radius is listed or shows on map
Kindly provide the useful solutions or links related to such scenario.
thanks
You can use markers to add locations in google maps. https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker
Google lists everything here. They also have a sample app on Github here. I'd suggest starting a sample map activity project in Android Studio, it should help you understand the basics of implementing a Google Map in your project.
GoogleMap map = ... // get a map.
// Add a marker at San Francisco.
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183))
.title("San Francisco")
.snippet("Population: 776733"));

Button on android map annotation

After a while of googling I cannot find what I need, I see some libraries which look to do it but I have already implemented the system using androids default methods.
I set the markers like so:
theMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_map32))
.snippet(strap));
However I need a 'detail disclosure button' like on iOS (transitioning app from iOS to Android) and I can't seem to add a button to the marker - is it possible using androids system?
This cannot be done.
from the docs
Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
in other words you cannot put a button in the infowindow and be able to use it. You will need to use a dialog of sorts if you want to do something like that
There is always some way.
A nice hack can be found here: https://stackoverflow.com/a/15040761/2183804
I haven't tested it myself, but from the comments there (and the amount of upvotes) we can deduce it works well.
You can track clicks only on Marker. If you want a button on marker - click on marker & show a dialog with buttons.

Android Navigation System

I have been asked to create a navigation system from scratch, that is not using google maps.
I already have the map of the city that I need to create the navigation system in autocad format.
I need to use this map somehow to create a navigation system but I dont really know where to start.
Can anyone point me in the correct direction?
Edit:
The map that I have is just an autocad file, that is, there is no meta data. How do I generate the metadata for the map?
Secondly, the application must calculate the shortest path between two points and if the user does not respect the path, the system must re-calculate the path.
Thanks
This is interesting. Its practically the exact project I've been working on the last few months. Take a look at the README for the project. It details how to go about doing what you're asking.
https://github.com/NCM-Team/Navigating-Carnegie-Mellon
To start, you can create a custom SurfaceView
public class MyMap extends SurfaceView {...
Next add this to your main layout:
<com.example.android.MyMap
android:id="#+id/my_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Lastly, in your main Activity's onCreate(...) method, add the line
MyMap map = (MyMap) findViewById(R.id.my_map);
You can now draw your map to this SurfaceView's Canvas.

Categories