Info Window on shapes(circle, polygon) in Android Maps App - android

I have an android app which one of its screens uses google maps, and I load some regions on it. I want to be able to click on a region/shape(circle or polygon) and an info window to appear. I am searching but I cant find enough information on how to show info windows on shapes, only on markers. Is that not a common practice? What should I do? Could anyone help, even theoretically? Any help or direction would be appreciated, thank you very much!

Create a customCircleOnClickListener (or don't and use the title and
snippet properties, as I am doing in step 3).
Then add:
mMap.setInfoWindowAdapter(new
CustomInfoWindowAdapter(MainActivity.this));
mMap.setOnCircleClickListener(customCircleOnClickListener());
Finally:
public GoogleMap.OnCircleClickListener customCircleOnClickListener() {
return new GoogleMap.OnCircleClickListener() {
#Override
public void onCircleClick(Circle circle) {
Log.d("MainActivity", "Clicked a ball!");
POIAnnotationCircle annotCircle = annotationsByCircle.get(circle);
markerForInfoWindow = mMap.addMarker(new MarkerOptions()
.alpha(0.0f)
.infoWindowAnchor(.6f,1.0f)
.position(annotCircle.getCoordinate())
.title(annotCircle.getTitle())
.snippet(annotCircle.getSnippet()));
markerForInfoWindow.showInfoWindow();
}
};
}

Related

Google map geoJson layer feature info on click

smart people :)!
Story: I have many layers what I have added to google maps in android. I am adding them by iterating - creating new GeoJsonLayer and calling method addLayerToMap(). I have created setOnFeatureClickListener on last GeoJsonLayer (Maybe here is the problem).
Problem: When I click on feature (LineString, Polygon) I receive information only about last Layer - polygon. Then I added mMap.setOnPolylineClickListener(), then click listener is going into correct methods - for LineString in PolyLineClick... etc, but here again is problem - how can I get information from Polyline about LineString properties, what I added to geoJson?
Question: What is the best approach to add layers to map , so I can manage click events and show LineString or Polygon properties for user?
Code example:
geoJsonLayer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() {
#Override
public void onFeatureClick(Feature feature) {
mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
#Override
public void onPolylineClick(Polyline polyline) {
//TODO show LineString properties
//Comes here when LineString clicked
}
});
mMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
#Override
public void onPolygonClick(Polygon polygon) {
//TODO show Polygon properties
//Comes here when Polygon clicked
}
});
}
Found solution - added all layers into 1 layer and everything works fine.

Android: find fastest route between 2 or more points depeding on streets in GoogleMaps

Am adding markers in my app on GoogleMaps,my markers allways are on streets.For example I have moore than 2 markers on map, I need to draw optimal route between them depending on streets.Is there any service to help me, or I need to create my own algorithm? Until now I worked a little with Google Elevation API and Google Direction API, but now I need Google Roads API, to find optimal roads between points? It must be something simmilar to my needs.
Consider using following library: https://github.com/akexorcist/Android-GoogleDirectionLibrary
GoogleDirection.withServerKey("YOUR_SERVER_API_KEY")
.from(new LatLng(37.7681994, -122.444538))
.to(new LatLng(37.7749003,-122.4034934))
.avoid(AvoidType.FERRIES)
.avoid(AvoidType.HIGHWAYS)
.execute(new DirectionCallback() {
#Override
public void onDirectionSuccess(Direction direction, String rawBody) {
if(direction.isOK()) {
// Do something
} else {
// Do something
}
}
#Override
public void onDirectionFailure(Throwable t) {
// Do something
}
});
Gradle
compile 'com.akexorcist:googledirectionlibrary:1.0.5'

Handling large amount of Points as VectorDataSource in nutiteq

hello every one hope you having a nice day
in order to load tons of markers (like 1mil) i am passing a list of MapPos to a VectorDataSource and trying to force it to live create the Points whenever related coordinates must be visible to the map now , but unfortunanly after a few try seems i dont know much about the map . would you please help me solve this puzzle ? thaanks alot
public static void createlustering(Projection proj,MapView mapView,Context context,final Bitmap bmp,float distance,float textSize,final ArrayList<MapPos> points){
AbstractVectorDataSource<Geometry> source = new AbstractVectorDataSource<Geometry>(proj) {
#Override
public Collection<Geometry> loadElements(CullState arg0) {
//what to do here
return list;
}
#Override
public Envelope getDataExtent() {
//what to do here
return null;
}
};
// source.addAll(points);
Clusterer mClusterer = new Clusterer();
mClusterer.addPointCluster(mapView, context,source,bmp,distance,textSize);
}
Unfortunately, that's a bit of a large amount to load with clusters. A more scalable solution, however, is to load them to your CARTO account and query them from there (overviews are used).
cf. android samples: CartoDBSQLDataSource and CartoSQLActivity
Additionally, if you're open to upgrading your SDK version, you can check out newer samples (master branch)

info window not showing

This is really killing me, I had them working then rewrote a bunch of code, and now it doesn't and I've got no version control! Any help is appreciated.
I create the markers in a Utility class.
private static MarkerOptions buildAmarker(LatLng location, String bankType, String locationDetails,
float markerColour) {
MarkerOptions binMarker = new MarkerOptions().position(location).title(bankType)
.snippet(locationDetails)
.icon(BitmapDescriptorFactory.defaultMarker(markerColour));
//.snippet(siteName + " | " + locationDetails);
return binMarker;enter code here
Then after my Loader completes, onLoadFinish, it hands me back various list of marker Options objects, I process them into Markers here:
private List<Marker> addBankListToMap(List<MarkerOptions> oneBankList) {
Log.i("ADDING a selected", "banks list to map");
// we need to save NEW lists of map attached markers OR can't change marker visibility
List<Marker> newBankList = new ArrayList<>();
for (int i = 0; i < oneBankList.size(); i++) {
MarkerOptions binMarker = oneBankList.get(i);
Marker newMarker = m_map.addMarker(binMarker);
newMarker.setVisible(true);
newBankList.add(newMarker);
//Log.e("!!!addingBank", newMarker.getTitle() + newMarker.getSnippet());
}
return newBankList;
Then end onLoadFinish with this
// setup click event for home marker to launch change home screen
m_map.setOnMarkerClickListener(EarthquakeActivity.this);
But none of the info windows appear if clicked. What am I missing? It was working till I rewrote my code, and I made a LOT of algorthmic improvements, I use arrays instead of half a dozen hashmaps, so the memory overhead should be less.
I can only think I've either deleted something crucial in a tidy up while being tired.
OR
I've blocked the info windows somehow. Some sleuthing to find the block, by disabling the changes, has failed. So it seems I've deleted something, forgotten something vital.
What do I need to do to get infoWindows working again? This is absolutely vital to my app. Arrggg!
#Override
public boolean onMarkerClick(Marker marker) {
if (marker.equals(homeMarkerFinal)) {
// TODO make this launch the change home address screen
Log.wtf("markerClicked", "!!!!");
Intent settingsIntent = new Intent(EarthquakeActivity.this, SettingsActivity.class);
startActivity(settingsIntent);
}
return true;
}
This is just for a single marker, the home marker. All the other markers are unnamed, I've got around 4000 markers stored in Lists as MarkerOptions. These lists are passed to addBankListToMap as oneBankList and converted into Markers, and attached to the map.
To show inforwindow you need call:
marker.showInfoWindow();
Pls put in in your onMarkerClick function.
Brilliant phongvan!, of course at some point I deleted this
else {
marker.showInfoWindow();
}
onMarkerClick.
Thankgod! My app had become useless! :) A thousand thanks phongvan.

Enabling "navigation" mode in skobbler Android API

I can't find a way to make my app, which currently implements SKmaps to the point of showing a route, show the route and follow the route like a car navigator.
example:
This is my "route loading" method:
#Override
public void onAllRoutesCompleted() {
SKNavigationSettings navigationSettings = new SKNavigationSettings();
navigationSettings.setNavigationType(SKNavigationSettings.SKNavigationType.REAL);
navigationSettings.setNavigationMode(SKNavigationSettings.SKNavigationMode.CAR);
navigationSettings.setCcpAsCurrentPosition(true);
navigationSettings.setFcdEnabled(true);
SKNavigationManager navigationManager = SKNavigationManager.getInstance();
navigationManager.setMapView(mapView);
navigationManager.setNavigationListener(MainActivity.this);
navigationManager.startNavigation(navigationSettings);
}
found it on the demo app code.
mapView.getMapSettings().setMapDisplayMode(SKMapSettings.SKMapDisplayMode.MODE_3D);

Categories

Resources