I'm adding hotspots to my map with the following code:
public void addMarker(MyCustomMarker marker) {
LatLng latLng = new LatLng(marker.getLatitude(), marker.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
}
What are the consequences of adding multiple hotspots with the identical lat/long? Will they both remain on the map and in memory, or will adding a new marker override the last one at that position?
Adding a new marker with identical lat/long will make both remain on the map and in memory.
The lat/long of a marker are just instance variables so no, this won't replace the existing Marker.
Related
I have implemented google map into my app. I have added a custom marker at my current location.I want to move the marker as the user moves, along with the map. I want to implement the functionality as in google maps navigation. While googling i found the following links but did not get the result. so can any one help me out ?
I have added this in onLocationChanged()
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
sourceLocation = latLng;
startPoint = new GeoPoint(latLng.latitude,latLng.longitude);
forNavigation = location;
// animation
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPositionMarker.getPosition(), 15));
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
These are the links which i found
Google map: moving marker and map together smoothly along with user?
How to smoothly keep moving current location marker in Google Maps v2 android
here is two solution you have.
Use onlocationtrue then it show you blue dot as your current location.
Use fused api for current location and create you marker in locationchanged.
for fused api you can check from here.
thanks
I'm using Google Maps Utils library for clustering markers.
I'm adding most of markers to cluster manager. The rest I'm adding to map (I don't want them to be clustered with others). My problem is that clusters are drawn above standard markers and cover them. Is there any way to change drawing order i.e. first clusters and markers above them?
Here's part of my code:
clusterManager = new ClusterManager<>(getActivity(), map);
clusterManager.setRenderer(new MyObjectRenderer(getActivity(), map, clusterManager));
clusterManager.setOnClusterItemClickListener(this);
map.setOnMarkerClickListener(clusterManager);
for (MyObject object : list) {
clusterManager.addItem(object);
}
clusterManager.cluster();
for (MyOtherObject object : otherList) {
map.addMarker(new MarkerOptions().position(object.getLatLng()).title(object.getName()));
}
I had a similar scenario: I was adding several locations to my ClusterManager and I needed a marker with the user position on top of all the other markers.
This worked for me:
Add user marker to map with zIndex to 1000 to ensure that it will be placed on top.
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(userLocation.getLatitude(), userLocation.getLongitude())).zIndex(1000);
map.addMarker(markerOptions);
Add markers to cluster manager.
for (MyObject object : objects) {
mClusterManager.addItem(object);
}
mClusterManager.cluster();
I've been trying to work out a method for my application to indicate when there are markers on the map that are outside of the current view/screen/bound/VisibleRegion.
For example, if there are current 5 markers on the map but the user is zoomed into a part of the map where they can't see any of the markers then I would like to be able to flag up to the user that there are markers on the map that they cannot see or something along those lines (it would be nice to be able to indicate in which direction the markers are from the current position).
I thought of using
LatLngBounds currentScreen = googleMap.getProjection()
.getVisibleRegion().latLngBounds;
but this would only be able to tell me which markers are in the current visibleRegion.
any help would be appriciated, thanks.
First, you should save all your markers somewhere. For example, in list
List<Marker> markers = new ArrayList<>();
Marker marker = mMap.addMarker(new MarkerOptions().position(new LatLng(55.123, 36.456)));
markers.add(marker);
After this you can check, are there markers outside your screen
LatLngBounds currentScreen = mMap.getProjection().getVisibleRegion().latLngBounds;
for(Marker marker : markers) {
if(currentScreen.contains(marker.getPosition())) {
// marker inside visible region
} else {
// marker outside visible region
}
}
Here in the code am displaying markers but if many markers have same latitude and logitude then the icons generated must have different colors or it must be moved a little bit so that we must be able to find that its in that location. Is it possible to do?
private void drawMarker(LatLng point, TextView icTag) {
Bitmap icBitmap = null;
icGen.setStyle(IconGenerator.STYLE_ORANGE);
icGen.setContentRotation(0);
icGen.setContentPadding(10,10,10,10);
tvImage.setTypeface(imageFont);
icGen.setContentView(tvImage);
icBitmap = icGen.makeIcon();
MarkerOptions markerOptions = new MarkerOptions()
.position(latlng)
.snippet("" + snip).position(point)
.icon(BitmapDescriptorFactory
.fromBitmap(icBitmap));
marker = googleMap.addMarker(markerOptions);
}
you can setup a bit of logic in your code so that older items are either bigger or with different colors or with different anchors.
Of course you need to check the distance of points before doing that, and i would suggest to use clustering which works fine for this kind of tasks
I have lat&long values from database.how to display markers based on lat &long values using android google map api v2.In original android google maps,we display markers based on concept itemoverlay. In v2,I dont know how to display markers.
dbAdapter.open();
Cursor points = dbAdapter.clustercall(Btmlft_latitude, toprgt_latitude,
Btmlft_longitude, toprgt_longitude, gridsize1);
int c = points.getCount();
Log.d("count of points", "" + c);
if (points != null) {
if (points.moveToFirst()) {
do {
int latitude = (int) (points.getFloat(points
.getColumnIndex("LATITUDE")) * 1E6);
int longitude = (int) (points.getFloat(points
.getColumnIndex("LONGITUDE")) * 1E6);
mapView.addMarker(new MarkerOptions().position(
new LatLng(latitude, longitude)).icon(
BitmapDescriptorFactory.defaultMarker()));
} while (points.moveToNext());
}
}
points.close();
dbAdapter.close();
That is mycode.I am getting lat&long values from database,but how to add markers based on lat &long values to map.
I read the android google maps api v2.In that have only give statically added data of markers
Use the Marker Class
An icon placed at a particular point on the map's surface. A marker icon is drawn oriented against the device's screen rather than the map's surface; i.e., it will not necessarily change orientation due to map rotations, tilting, or zooming.
A marker has the following properties:
Anchor
The point on the image that will be placed at the LatLng position of the marker. This defaults to 50% from the left of the image and at the bottom of the image.
Position
The LatLng value for the marker's position on the map. You can change this value at any time if you want to move the marker.
Title
A text string that's displayed in an info window when the user taps the marker. You can change this value at any time.
Snippet
Additional text that's displayed below the title. You can change this value at any time.
Icon
A bitmap that's displayed for the marker. If the icon is left unset, a default icon is displayed. You can specify an alternative coloring of the default icon using defaultMarker(float). You can't change the icon once you've created the marker.
Drag Status
If you want to allow the user to drag the marker, set this property to true. You can change this value at any time. The default is true.
Visibility
By default, the marker is visible. To make the marker invisible, set this property to false. You can change this value at any time.
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"));
You have to use the method GoogleMap.addMarker(MarkerOptions);
I've explained this in a tutorial on my blog:
http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html
On this blog, you'll find some more posts concerning the new Maps API:
Move the map to current or some location
Create the custom InfoWindow
Associate geodata or objects to a marker
I'm guessing the issue is that you are multiplying your latitude/longitude values by 1E6 instead of dividing them by 1E6. If your stored values came from GeoPoints, that might be your issue. Otherwise, the way you are adding the Markers is fine and should work.
i.e. the lat/lng values you pass to new LatLng() should look like 45.4,-95.5 NOT 45400000,-95500000
Check out the following code:
//mMap is a GoogleMap and point is a GeoPoint
this.mMap.addMarker(getMarker(point, drawableId))
...
public MarkerOptions getMarker(GeoPoint point, int drawableId)
{
return new MarkerOptions()
.position(new LatLng(point.getLatitudeE6() / 1000000.0, point.getLongitudeE6() / 1000000.0))
.icon(BitmapDescriptorFactory.fromResource(drawableId));
}