I am building an Android application that shows the user his/her current location (using MyLocationOverlay), and I am also using a LocationManager/LocationListener to get the user's location every 15 seconds, which is then used to query a web service and in return I plot points using an ItemizedOverlay.
This is all working with no problems.
Should I be using BOTH MyLocationOverlay as well as LocationManager/LocationListener, however? It seems redundant. What would you do? From what I can see, MyLocationOverlay uses the LocationManager in the background to constantly receive location updates, anyway.
Thanks!
The MyLocationOverlay does a little more such as adding the overlay to the map, showing the error radius and making it cool and blinky! There is nothing wrong with using it in conjunction with getting your own updates. In my app I decided not to use it because I wanted to change the way that it looked so that it was more like what you see in the Maps app where the MyLocationOverlay is an arrow that shows what direction you're facing. It's really a matter of preference.
Related
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.
setLocationEnabled is a attribute that shows a button on the top of the map that makes the map go to the current place.
But I want to "hide" this Button and call the method on the another custom button. Is there a way? I don't wanna to create a big code to go to current location, it's not fast. I just wanna a button with the same function of the setLocationEnabled(true).
How do I do that?
I've dealt with a similar problem and I found a pretty detailed solution from here Google map for android my location custom button
Have fun!
As you may know, you can hide the current location button with the following:
UiSettings.setMyLocationButtonEnabled(false);
Now, if you want to perform this task manually, you'll have to do some work on your own. First, you will need to acquire the user's current location. This can be acquired (and updated) by overriding the onLocationChanged function of the LocationListener implementation. If you are unclear on how to do this, checkout the documentation describing it. This may prove useful as well!
Secondly, you'll need to target the user's location by setting the map's camera to look at it, and (possibly) set a marker in the location. Here's the function I used in one of my recent apps describing how to do so:
public void moveToLocation(Location input) {
Double lat = (double) (input.getLatitude());
Double lon = (double) (input.getLongitude());
final LatLng location = new LatLng(lat, lon);
setLocMarker(location);
mainMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 16));
//if you want the camera to have an "animated" effect, you can perform the following
//mainMap.animateCamera(CameraUpdateFactory.zoomTo(16), 4000, null);
}
For more information regarding camera effects and animations, refer to this documentation.
I'm developing an android application in which I've used Google Map v2 API.
I've placed one marker on the map, now I want to set its "OnLongClickListener".
As I can see from Eclipse there are only two listeners available for marker:
googleMap.setOnMarkerClickListener(listener);
googleMap.setOnMarkerDragListener(listener);
Could anybody show me any easy way to handle marker's LongClick event??
I've gone through two solutions here:
Setting a LongClickListener on a map Marker
How to detect long click on GoogleMap marker
as both of the solutions you posted have shown - there is no long click event on markers in the maps api. the first link you posted had a solution that might be able to suit your needs but isn't perfect by any means
i would suggest going here to the gmaps issues page and browsing through the feature requests and adding one if it does not exist
I have a pair of questions about google maps for android. I decided to use a webview to display google maps due to the compatibility for the google maps api, so i'm having problems with really simple things (at least i think the are simple).
1) At the start of the application, my webview shows the map with a very low zoom. How can i set a higher zoom from the beginning? There are +/- buttons, but they are pretty uncomfortable.
2) How can i put a mark on the map? With the api, i have just to use the
google.maps.Marker
, but i don't know ho to use it with a webview.
I think that both the problems can be solved using javascript, but i'm new and i really don't know how to solve them. Thank you very much.
For the marker, you could create a javascript function to add a marker, and then on the WebView load a url like javascript:addAMarker("AddItHere");. I don't get what you mean the buttons are uncomfortable for the +/-.
I am looking for some help....
Firstly I have a database server side with a numerous amount of locations(longs +lats)
Now there are upto a 1000 for one city alone. At the moment, my android device all the information at once. I then create 1000 itemized overlays and add them to the map view.
This in turn makes my emulator and phone run slow.
One idea I had was to zoom in on a location and then download and place a subset of the overlays on the map view.
Trouble I have with this
1. When I scroll on the map I don't know what event to register a listener to.
2. When the user zooms out I will still create the large number of itemised overlays.
My question to you guys is,
How could I overcome these problems? Or how would you go about doing this?
The solution Would be something similar to how google maps works. U c a not so detailed map when u zoom out, but when u zoom in it shows you a detailed map that reloads as you move around
I then create 1000 itemized overlays and add them to the map view.
Ummmm... please tell me that this is a typo, and you meant "1000 OverlayItems", not "1000 ItemizedOverlays".
1000 OverlayItems might be bad enough -- ItemizedOverlay isn't really designed for that many points.
When I scroll on the map I don't know what event to register a listener to.
I don't think there is a straightforward solution here. I think others have kinda reverse-engineered the touch events and are listening on those. See Android Maps get Scroll Event for more.
When the user zooms out I will still create the large number of itemised overlays.
Use a prioritization scheme. What you see with Google Maps is that only the top N items are shown, where "top" is based on some sort of priority mechanism.