I'm trying out the info balloon from: https://github.com/jgilfelt/android-mapviewballoons and it's working perfectly. One thing I'm missing is the ability of setting the current location. Does anybody know how to precisely implement that function?
Thanks in advance !
Yes, for example I have some url variable which I display in baloon and my onBaloonTap looks like this, where c is context
#Override
protected boolean onBalloonTap(int index, OverlayItem item) {
String url = WebService.upcomigEvent;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
c.startActivity(i);
return true;
}
You can track position by implementing the LocationListener interface, or by using the MyLocationOverlay class. In both, the method onLocationChanged is available, and you can provide it with your own location object that you create, specifying the lat/lng/alt. This in effect 'spoofs' the users location, and this might not be what you want. If you just want to scroll the map to a specific point you can use the animateTo method available in the MapController.
Related
Hi everyone I am using the GoogleMaps Gms.Maps class to show a map on my app (Xamarin.Android).
I am trying to make it so when you click on a marker it will take you to a specific page on my mobile app. however it seems the markers already have on click functions that centre it and display the title. I haven't created this and also can't find it (see below)
any idea how I would edit this function or create a new one?
thanks,
Implement Android.Gms.Maps.GoogleMap.IOnMarkerClickListener on your Activity, Fragment or in a separate class and assign that to the GoogleMap instance via the SetOnMarkerClickListener method.
Example:
public class MyMarkerClickListener : Java.Lang.Object, IOnMarkerClickListener
{
Context context;
public MyMarkerClickListener(Context context)
{
this.context = context;
}
public bool OnMarkerClick(Marker marker)
{
Toast.MakeText(context, $"{marker.Title} was tapped", ToastLength.Long).Show();
return true;
}
}
Usage:
googleMap.SetOnMarkerClickListener(new MyMarkerClickListener(this));
Note: Normally the listener would be assigned in the OnMapReady callback
Google Docs: GoogleMap.OnMarkerClickListener
Returns:
true if the listener has consumed the event (i.e., the default behavior should not occur); false otherwise (i.e., the default behavior should occur). The default behavior is for the camera to move to the marker and an info window to appear.
Well what #SushiHangover has answered is right but the easier way of doing it would be adding a marker click event:
Googlemapsobj.MarkerClick+= (s,e)=>
{//yourcodeforNextPage };
Here you wont have to worry about the default behaviour as it will leave the page as soon as it is clicked.
How Can I get exact number in bucket of cluster manager?
Can anyone give me an example ? how to get exact like 42,35 instead of 20+,50+ etc ?
May be this is not the best answer but it has been work for me.
public class CustomClusterClass extends DefaultClusterRenderer<Data> {
public CustomClusterClass(Context context, MapboxMap map,
ClusterManagerPlugin<Data> clusterManagerPlugin) {
super(context, map, clusterManagerPlugin);
}
#Override
protected String getClusterText(int bucket) {
return super.getClusterText(bucket).replace("+", "");
}
#Override
protected int getBucket(Cluster<Data> cluster) {
return cluster.getSize();
}
}
If you check the documentation of clustering in Google Maps Android API, you will see here on how to customize the marker cluster.
It is stated here that the ClusterManager constructor creates a DefaultClusterRenderer and you can change the ClusterRenderer and the Algorithm using the setAlgorithm(Algorithm<T> algorithm) and setRenderer(ClusterRenderer<T> view) methods of ClusterManager.
The DefaultClusterRenderer provides a base to start from, and to override this defaults, you need to subclass the DefaultClusterRenderer.
For more information, you can check this thread and this sample code on how to customize the marker cluster.
You have to customize DefaultClusterRenderer class.
//to get the exact count of map clustering
protected int getBucket(Cluster<T> cluster) {
int size = cluster.getSize();
return size;
}
refer this link https://github.com/MadhuProjectWorks/GoogleMapClustering
For anyone else visiting later:
As far as my experience with Android is concerned, you will need to use a custom cluster if you want to display the exact number of items in a cluster. I too have been searching for a way to show the exact number while using the default cluster marker / circle.
So, just as everyone is pointing out, check out the sample code here. You will then need to use the below code to get the exact cluster item count:
override fun onBeforeClusterRendered(cluster: Cluster<MyClusterItem>?, markerOptions: MarkerOptions?){
//... create your view
val clusterSize = cluster?.items?.size
//user clusterSize on your custom view
}
Once again, be patient and go through the code in the link and create your own view and eventually you will be using the cluster size and you want it to be.
I am using skobbler map for Android. I do not require current location to pointed on the map, so I am not registering for the current location listener and skobbler map itself adds an default current location pin on the map. Please check the image attached. , please tell me how to not display this. And, by default the maps takes to Berlin, Germany can this be avoided? If yes, how?
You can set the behavior of the default position annotation with mapView.getMapSettings().setCurrentPositionShown(false).
To center the map on a desired location use mapView.centerMapOnPosition(skPosition).
Where mapView is your SKMapSurfaceView instance.
Please check the below code hope its help you.As its working at my end.
#Override
public void onCurrentPositionUpdate(SKPosition skPosition) {
this.currentPosition = skPosition;
SKPositionerManager.getInstance().reportNewGPSPosition(this.currentPosition);
mapView.animateToLocation(skPosition.getCoordinate(), 7);
mapView.animateToZoomLevel(7);
}
You can try to call in onSurfaceCreated:
SKCoordinate coord = new SKCoordinate(-37.585162f, 40.418143f);
mapView.setPositionAsCurrent(coord, 0, true);
mapView.setZoom(4);
I am working on android map app in xamarin android. I want to handle the zoom event of map. Can anybody tell me how can I do this in xamarin android using map.SetOnCameraChangeListener ..
Regards
This is a bit late of an answer, but this really helped me. Should have everything you need.
http://pastebin.com/dgdiDk2N
Basically you need to implement the interface:
public class MapTab : Fragment, GoogleMap.IOnCameraChangeListener
Then you can set the listener as such:
map.SetOnCameraChangeListener (this);
And you will also need to add the method OnCameraChange:
public async void OnCameraChange (CameraPosition cameraPos)
{
//Do your things here when the camera updates
}
I'm developing an application on Android with the use of Google Map.
I've successfully put multiple bitmaps on the map as shown on the figure above.
Is it possible to detect which bitmap the user has clicked on, so that the application will redirect the user to a page which contains information about the place clicked?
Here you will need to put some logic to capture which bitmap Image was clicked.
One technique which works in my case is to override a method in your ItemizedOverlay class
protected boolean onTap(int index) {
// Here you get the index of which bitmap image was tapped on
// You can map this index to the related activity you need to open by mean of your logic
OverlayItem item = mOverlays.get(index);
Intent intent=new Intent (context,YourActivity.class);
context.startActivity(intent);
return true;
}