Get placemark from getPlacemarks with Google Maps Android API utility library - android

I'm using this library to show a kml markers in a map in Android Maps V2.
I´m trying to get the lat and lon from a kml layer to do zoom directly to a placemark after add it to a map.
I tried to do this:
layer = new KmlLayer(mMap,R.raw.ruta, this );
layer.addLayerToMap();
for (KmlPlacemark act : layer.getPlacemarks()){
System.out.println("hi");//not iterate
}
but it doesn´t enter in the loop I read this kml-feature but don't work as is

You will have to read the 1st container of the KML-layer before attempting to read information about the placemarks:
KmlContainer = layer.getContainers().iterator().next();
if (kmlContainer == null) return;
for (KmlPlacemarks placemark : kmlContainer.getPlacemarks()) {
// Do the placemark magic here!
}

Related

draw geoJson on map mapbox

Is there another way for add geoJSON polygon to map using mapbox sdk 9.0 stable on android?
I have the following but not sure if it's correct:
GeoJsonSource source = new GeoJsonSource("geojson", geoJsonString);
mapboxMap.addSource(source);
mapboxMap.addLayer(new LineLayer("geojson", "geojson"));
This example from the Mapbox documentation shows how to add a GeoJSON polygon to your map with the Mapbox Maps SDK for Android. The relevant code is in the onMapReady callback, extracted below (I omitted the code related to adding a click listener, since that is not relevant for your question);
#Override
public void onStyleLoaded(#NonNull Style style) {
// Add the GeoJSON as a source to the map.
addGeoJsonSourceToMap(style);
// Create FillLayer with GeoJSON source and add the FillLayer to the map.
if (style != null) {
style.addLayer(new FillLayer(geoJsonLayerId, geoJsonSourceId)
.withProperties(fillOpacity(0.5f)));
}
}
The addGeoJsonSourceToMap helper method in this example loads the GeoJSON from an external URI, but in your case the first two lines of your provided code snippet would replace the addGeoJsonSourceToMap(style); call.
A FillLayer is used rather than a LineLayer since, per the linked API reference documentation:
FillLayer:
A filled polygon with an optional stroked border.
LineLayer:
A stroked line.
1. Try adding the Source:
// WARDS – 2020 – SOURCE
// url = 'https://opendata.arcgis.com/datasets/845bbfdb73944694b3b81c5636be46b5_0.geojson';
map.addSource(
'ward-source', {
type: 'geojson',
data: 'Wards.geojson'
}
);
2. and the Layers:
// WARDS FILL
map.addLayer({
'id': 'wards-fill',
'type': 'fill',
'source': 'wards-source',
'layout': {},
'paint': {
'fill-color': '#627BC1',
'fill-opacity': [
'case',
['boolean', ['feature-state', 'hover'], false],
1,
0.5
]
}
});

Google Static Maps Polyline Issue

I am attempting to create a Google Static Map with a Path drawn on it. I am receiving a Static Map back, but the map is zoomed really far out and the poly line is cutting clear through continents and oceans.
Am I building the Google Static Maps API URL Properly? If I am not, what can I do to change it. The polyLine List is retrieved by using a Direction API call.
Separating the List polyLines and creating the Path portion of the URL
if (polyLines != null && polyLines.size() > 0) {
url.append("&path=" + URLEncoder.encode("weight:10|color:blue|enc:", "UTF-8"));
for (String polyline : polyLines) {
url.append(URLEncoder.encode(polyline, "UTF-8"));
}
}
HERE IS THE FINAL URL
https://maps.googleapis.com/maps/api/staticmap?size=1080x1080&scale=2&format=png&markers=icon%3Ahttps%3A%2F%2Fdial7.limosys.com%3A7771%2FJlimoWSJson%2Ficons%2Fpu_marker_64.png%7C40.8830388%2C-73.9498278&markers=%7Cicon%3Ahttps%3A%2F%2Fdial7.limosys.com%3A7771%2FJlimoWSJson%2Ficons%2Fdo_marker_64.png%7C40.8362248602332%2C-73.94620008246969&path=weight%3A10%7Ccolor%3Ablue%7Cenc%3A%7D%7DoxFhijbMb%40l%40r%40p%40r%40h%40f%40V%5ERz%40XdFjAgnoxFdrjbMj%40iAXk%40%5Eu%40Vm%40Vm%40LWDKPc%40khoxFtgjbM%7C%40h%40LHJDZPd%40PPFjA%5EdB%60%40xCf%40%7CCl%40nF%7E%40fAXbAVx%40ZhAd%40NFNFf%40VnAp%40lAv%40nCzBbAp%40t%40d%40n%40b%40JDb%40Xt%40%5E%7E%40%60%40p%40Td%40LZFPB%5EF%60ALxATlALp%40FT%40VB%5EBV%3FrBDP%40V%40VBP%40NBND%5CHRFTFTLNHRJPNNJXV%5E%5CTTZZ%60%40XNJVNb%40V%5CPb%40TZNRJl%40ZXR%5ER%5CVXX%5Eb%40lAtAnAxANPDFx%40%7E%40axkxF%60albMJPHMBG%40A%40A%40A%40%3FB%3FB%3FB%3FB%40ZNRZXd%40X%5Cf%40t%40tArAnA%7E%40JFD%40LHJDB%40FDv%40%60%40p%40ThJvC%7CBhAdCxAr%40%5CbAj%40nBr%40tA%5EXHB%3FXH%40%40F%3FZJB%40%40%3FB%40B%40H%40%40%40%40%3F%40%3F%40%40D%40%40%3F%40%40D%40JB%40%3F%40%3FHB%40%3FLDj%40LDBHDHHDDFHFLBJ%40HBL%3FJ%3FD%3FD%3FLABAHCLCLGLOPMHGBQBM%3FQCIEGGIEEGCGGIEQEMAO%3FO%3FQBO%40Q%40KBUDSDYDa%40%40Y%3FCCq%40%5CuCd%40gE%7CCoXv%40uG%7E%40cIRyAlBiPbAyIv%40yGv%40mHPkBD_%40PoB%40%3FViCioixFreibMVe%40%40C%3FABKBMBSHs%40DY%3FC%40A%3FEHo%40Jy%40%40CBQ%40M%40M%3FABSF%5BF%5DPc%40FOHKJIFAJEHAJ%3FL%40HBFBHFJJNVBLBH%40DLt%40Db%40B%5CBRDV%3F%40DT%40BDLT%60%40HFFDFDLFLDLDJBL%40J%40J%3FXAx%40Gz%40Cp%40Ej%40%3F%5C%3FR%40D%3FPGLBLBXFF%40FDLFNLLN%40%40kshxFxbibMJBB%40%40%40%40%40%40BBFBJJ%60%40FTHXLXJPHJHJRLLDPFNBRBJ%40P%40N%3FPARCREPELGNITMNMJK%5Ce%40%5Ci%40cehxF%7CdibM%7C%40%3Fh%40%40PBT%40L%40J%40TDf%40HND%5CHRFPFVJXNHDXVZXtCxCb%40d%40XVXRRNPJRHb%40RXJTHb%40PVLTNVNNNh%40d%40RRafgxFrwibMn%40%60At%40jAHLLNPN%5E%5CRLTP%5ENl%40RbATD%40JB%5EHD%40rCj%40xDp%40onfxFvdjbMRFf%40cBPk%40alfxFn%60jbMIk%40ESESGOEMMMSSeAs%40WYIcAYqCKeACW%3FK%3FIyrfxFboibMJm%40KAI%40SBWBWHc%40VMHKHMNORGHKRS%60%40

Google Map API v2 Heatmap not showing all locations

I'm trying out the Google API V2 Heatmap (Android) which was introduced this february and it's not working entirely. I'm not sure if it's the same problem as Google Maps API v2 HeatMap Won't Reliably Display (and I can't contact him by comments because I don't have enough rep.. :c ).
Using locations from file
Anyway, what I was trying to do was an App with just a GoogleMap and the same locations as in their guide (https://developers.google.com/maps/documentation/android/utility/heatmap) and when I launch it, I can only see 3/5 locations.
I tried adding more points and still, it's consistently not showing them all, but I can't see a pattern or something. The code is the same as in their guide.
private void addHeatMap() {
List<LatLng> list = null;
// Get the data: latitude/longitude positions of police stations.
try {
list = readItems(R.raw.police_stations);
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of locations.", Toast.LENGTH_LONG).show();
}
// Create a heat map tile provider, passing it the latlngs of the police stations.
mProvider = new HeatmapTileProvider.Builder()
.data(list)
.build();
// Add a tile overlay to the map, using the heat map tile provider.
mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
}
private ArrayList<LatLng> readItems(int resource) throws JSONException {
ArrayList<LatLng> list = new ArrayList<LatLng>();
InputStream inputStream = getResources().openRawResource(resource);
String json = new Scanner(inputStream).useDelimiter("\\A").next();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
double lat = object.getDouble("lat");
double lng = object.getDouble("lng");
LatLng latLng = new LatLng(lat, lng);
list.add(latLng);
}
return list;
}
Trying with weighted locations had the same result, some of them showing and some not.
Using locations "onClick"
In this case, normal LatLng were added and the map was updated until I got to the equator and then it stopped :p.
For the case of weightedLatLngs, it didn't update/show any :(
That's basically it... I don't know where to look for more information, whether it's something with the API, the device or something else.
Does anyone know why this might happen and/or where to look for a solution ?
Thank you in advance !
Btw, I'm using Android 4.0.4 on a Samsung Galaxy S Duos if that may prove useful..
The Googlemaps API for Heatmap only allows for 1,000 plotted points. You can reduced that by filtering out your original data or by converting to "weighted locations".
This looks like it was caused by this bug, where bounds calculations were excluding max values.
This is now fixed.

Tool to draw polygon on google map by passing coordinates

I am doing android app for field drawing and now I am making share function. Is there are any way to pass field coordinates from mobile to maps.google.com, make link, and send this link for example to friend via sms or email, that he just need to push the link and my drawed field will show up to him in browser? Is there any tool to do this or I need to create some web app for this?
Try out it
// To draw boundray on map
private void drawPolygon() {
polygonOptions = new PolygonOptions(); // consider new options
setStrokeWidth();
for (LatLng latLng : drawCoordinates) {
Marker marker = googleMap.addMarker(new MarkerOptions().position(latLng).title(latLng.toString()));
marker.setVisible(false);
polygonOptions.add(marker.getPosition()).strokeColor(Color.RED);
polygonOptions.fillColor(Color.TRANSPARENT);
polygonOptions.visible(true);
}
List<LatLng> points = polygonOptions.getPoints();
if (!points.isEmpty()) {
polygon = googleMap.addPolygon(polygonOptions);
Log.i("Poly lines","Successfully added polyline on map");
}
}

Connect GeoPoints Android

I have an Android application and I'm trying to populate a Google Map with a route, this route is store on a JSON array this way:
JSONArray.getString("points") = ["-33.45591917507404, -70.59198361376951","-33.453484420618416, -70.61635952929686"]
So in this case I have
Point A=(-33.49088437162095, -70.64043194102163) and
Point B=(-33.49423964397045, -70.63992768572683)
And my route or path is A-----B
I'm new to Android and I was wondering how to get this to work. Also, in this case my route is A-----B, but it can also be A----B----C----D. I can have any number of points on the path.
One thing you can try is the Google Maps Polyline object: https://developers.google.com/maps/documentation/javascript/reference#Polyline You specify to setPath() an ordered list of the points (either an Array of LatLng or an MVCArray or LatLng), you want to connect together on the map, and Google Maps will make a polyline for you to your specifications.
// path = Array of LatLng or MVCArray of LatLng
routeLine = new Polyline();
routeLine.setPath(JSONArray);
In your case, passing JSONArray into setPath should work OK.
If you want to get fancy and incorporate directions, you need to use the Google Directions API. https://developers.google.com/maps/documentation/javascript/directions
// All waypoints must be stopovers for the Directions service to optimize their route.
// start & end are of type String or LatLng, waypts is an array of String or LatLng
request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: [type Boolean],
travelMode: [type TravelMode]
};
// go on and actually perform the request
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
// if successful, this will run
}
});
Once you finish constructing your object, you should be able to display it by running setMap(map:Map), such as
routeLine.setMap(map)

Categories

Resources