How to manage Android gmaps overlays order - android

My desired goal is to add a TileOverlay in mbtiles format and rendering some gemetric object (mainly lines and polygons) in KML format.
The problem is that the MapBox map covers my KML polygons and i don't know how to manage the rendering order.
Via code i tried to load on map firstly the mbtile and then the KML polygons, with no luck.
I attach the code for further considerations
TileOverlayOptions opts = new TileOverlayOptions();
MapBoxOfflineTileProvider provider = new MapBoxOfflineTileProvider("/path/to/file.mbtiles");
opts.tileProvider(provider);
mbTileOverlay = mMap.addTileOverlay(opts);
KmlLayer layer = null;
try {
layer = new KmlLayer(mMap, R.raw.mypolygons, mContext);
layer.addLayerToMap();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Thanks for your help
Here is a link to the KML used

The polygons defined in your KML don't have the drawOrder property set (see this change) so the zIndex is set to the default (0).
As you don't define a zIndex for your MapBoxOfflineTileProvider it's also defaulted to 0. Try defining your TileOverlayOptions like this:
TileOverlayOptions opts = new TileOverlayOptions();
opts.zIndex(-1);

Related

Object already owned exception on Esri Native Xamarin Android

I want to display downloaded layers on the map. The map which I am using is also an offline Esri map. The problem is that when I am adding layers on the map using myMap.OperationalLayers.Add();. I am getting an Exception i.e Object already owned.
Code:
if (featureLayerDict.Any())
{
// Remove the previously applied layers
if (myMap.OperationalLayers != null)
{
myMap.OperationalLayers.Clear();
}
// Select the LayerIds, which are based on if Parent Layer is selected
var selectedMapLayerIds = mapLayers.Select(l => l.ID).ToList();
foreach (var dictItem in featureLayerDict)
{
try
{
// Add the layer to maps operational layer only if its parent layer is selected and if its present in the userlayers
if (userLayers.Contains(dictItem.Key) && selectedMapLayerIds.Contains(dictItem.Key))
{
myMap.OperationalLayers.Add(dictItem.Value);
}
}
catch (Exception ex)
{
continue;
}
}
}
A FeatureLayer can only be owned by one map at the same time.
So after close the first map, you have to make null the references to their layers or just do:
myMap.OperationalLayers.Clear();
at the beginning of the method that adds the layers to the map.

Get placemark from getPlacemarks with Google Maps Android API utility library

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!
}

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.

Parsing local gpx file in Android

I followed this example to parse a local GPX file in Android:
http://android-coding.blogspot.pt/2013/01/get-latitude-and-longitude-from-gpx-file.html
All works fine to access "lat" and "long" but I need also to get the "ele" value but all my tentatives were unsuccessful.
Anyone can give me some hits to do that?
Thanks in advance!
Best regards,
NR.
I will add my library for GPX parsing to these answers: https://github.com/ticofab/android-gpx-parser. It provides two ways to parse you GPX file: once you obtain / create a GPXParser object (mParser in the examples below), you can then either parse directly your GPX file
Gpx parsedGpx = null;
try {
InputStream in = getAssets().open("test.gpx");
parsedGpx = mParser.parse(in);
} catch (IOException | XmlPullParserException e) {
e.printStackTrace();
}
if (parsedGpx == null) {
// error parsing track
} else {
// do something with the parsed track
}
or you can parse a remote file:
mParser.parse("http://myserver.com/track.gpx", new GpxFetchedAndParsed() {
#Override
public void onGpxFetchedAndParsed(Gpx gpx) {
if (gpx == null) {
// error parsing track
} else {
// do something with the parsed track
}
}
});
Contributions are welcome.
you have the "Node node = nodelist_trkpt.item(i);" in your first loop.
Get the child elements from this node an run through these child elements.
e.g.:
NodeList nList = node.getChildNodes();
for(int j=0; j<nList.getLength(); j++) {
Node el = nList.item(j);
if(el.getNodeName().equals("ele")) {
System.out.println(el.getTextContent());
}
}
Update: I've added parsing "ele" element as well, so this code could match your requirements.
I will propose different approach: https://gist.github.com/kamituel/6465125.
In my approach I don't create an ArrayList of all track points (this is done in the example you posted). Such a list can consume quite a lot of memory, which can be an issue on Android.
I've even given up on using regex parsing to avoid allocating too many objects (which causes garbage collector to run).
As a result, running Java with 16Mb heap size, parsing GPX file with over 600 points, garbage collector will be run only 12 times. I'm sure one could go lower, but I didn't optimize it heavily yet.
Usage:
GpxParser parser = new GpxParser(new FileInputStream(file));
TrkPt point = null;
while ((point = parser.nextTrkPt()) != null) {
// point.getLat()
// point.getLon()
}
I've successfully used this code to parse around 100 Mb of GPX files on Android. Sorry it's not in the regular repo, I didn't plan to share it just yet.
I've ported the library GPXParser by ghitabot to Android.
https://github.com/urizev/j4gpx

How to use .shp file in android

I want to create application to show offline map using GIS shape file(.shp) any one have idea that how to use shape file to display map in android.
Thanks in advance
If you are loading data from SD card, you can work with openmap it has a class SHapefile and try to transform your shapefile to an graphicslayer it will work i've already done it.
static public GraphicsLayer SHPtoPOINT(String shpfile) {
SpatialReference lSR = SpatialReference.create(26192);
Envelope lEnvolope = getSHPEnvelope(shpfile);//to create an extent for your graphics layer
GraphicsLayer graphicLayer = new GraphicsLayer(lSR, lEnvolope);
try {
File file = new File(shpfile);
ShapeFile shp = new ShapeFile(file);
ESRIPointRecord e = (ESRIPointRecord) shp.getNextRecord();
SimpleMarkerSymbol c_point = new SimpleMarkerSymbol(Color.BLACK, 1,
STYLE.CIRCLE);
while (e != null) {
graphicLayer.addGraphic(new Graphic(new Point(e.getX(), e.getY()), c_point));
e = (ESRIPointRecord) shp.getNextRecord();
}
shp.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return graphicLayer;
}
Source
EDIT:
BBN Technologies' OpenMap TM package is an Open Source JavaBeans TM
based programmer's toolkit. Using OpenMap, you can quickly build
applications and applets that access data from legacy databases and
applications. OpenMap provides the means to allow users to see and
manipulate geospatial information.
Link to OpenMap info.

Categories

Resources