Lua Service2Media Mobile - android

Im trying to create a map using the service2media platform for mobile applications and i get this error - attempted index of non table : null on the line where i create a new map instance. Any idea why? The map view takes in coordinates and radius as parameters.
MapView ={}
function MapView:loadView()
local mapView = M2Map.newNativeMapView(Coordinate(0,0), 3000);
self:addSubView(mapView);
end

First of all you have to instantiate the Coordinate class using Coordinate.new(). Depending on the version of the platform you possibly have to use the MapView class instead of the M2Map class. In the latter case you have to rename your Lua class name in order to prevent name collision.
function MapView:loadView()
local mapView = M2Map.newNativeMapView(Coordinate.new(0,0), 3000);
self:addSubView(mapView);
end

Related

How to pass custom coordinates to map box navigation launcher?

Mapbox provides good Navigation SDK for Android, and what I have been trying to do is pass custom lat and lng's to mapbox navigation launcher. But its taking current user location and i would like to pass the custom coordinates . Is that possible?
You need to build a DirectionsRoute and then eventually give it to the NavigationLauncherOptions.Builder.
You can build a route with a custom origin instead of the device location.
Also, you can add custom waypoints.
Create a waypoint via the Point class. Point wayPoint = Point.fromLngLat(longCoordinate, latCoordinate);
Once you get the route from the response, you can eventually give it to the options builder before starting the NavigationLauncher.

How to update existing line layer in MapBox

Here is mapBox sample to draw a line geometry.
private void onStyleLoaded(Style style) {
initRouteCoordinates();
style.addSource(new GeoJsonSource("line-source",
FeatureCollection.fromFeatures(new Feature[]{
Feature.fromGeometry(LineString.fromLngLats(routeCoordinates))})));
style.addLayer(new LineLayer("lineLayer", "line-source")
.withProperties(PropertyFactory.lineDasharray(new Float[] {0.01f, 2f}),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineWidth(5f),
PropertyFactory.lineColor(Color.parseColor("#e55e5e"))));
Point point = routeCoordinates.get(0);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(point.latitude(), point.longitude()), 17));
}
I need to add more points and update the line. As you can see in the example line geometry is given to the source layer at the construction time. I couldn't find any api to add a point to the current line later.
Should I remove this line and redraw a new one ? Isn't there a better approach ?
You can add the "line-source" source and corresponding "lineLayer" layer once, and set the data contained by the source each time you want to add more points to update the line. Namely, each time you want to update the data rendered by the LineLayer:
Add the newly acquired coordinate to your existing GeoJSON source, stored in a variable called data. (I'd recommend storing new GeoJsonSource("line-source", ... in a data variable rather than creating it inline within the call to style#addSource, so that you can access it later to update).
Execute style.getSourceAs("line-source").setGeoJson(data).
Alternatively, you could use geoJsonSource.setGeoJson(Feature.fromGeometry(LineString.fromLngLats(updatedRouteCoordinates))) rather than setGeoJson(data), which might be more convenient depending on your use case.
You can modify the implementation according to your specific needs, but the general idea is that you only need to update the existing source's data, and not its corresponding layer, each time you want to update the line. This concept is described in the modify properties documentation for the Mapbox Maps SDK for Android. To quote the documentation:
sources and layers aren't immutable so they can be modified anytime during the map render

Using polygon class in google maps without having maps view

I am developing an Android application where I need to check whether a GPS point lie inside a region (or polygon). I am therefore planning to use Polygon class provided by Google Maps. But, this require a map view to construct a polygon. I don't want to use a map view. Kindly tell if there is a class or some API by which polygon can be used. I have come to know of a PolyUtil class but it requires importing another library.
Thanks,
Arpit
Use this lib android-maps-utils:
PolyUtil.containsLocation(LatLng point, java.util.List<LatLng> polygon, boolean geodesic)

How to move a Mapsforge Layer (Marker) in Android

I am using Mapsforge 0.5 for android. I have added some markers to the map with:
map.getLayerManager().getLayers().add(layer);
What I am trying to do is change the position of an existing layer. I have a reference to the object stored, but there isn't any way to move the marker. There is only a getter for the position
layer.getPosition() : LatLong
The latitude and longitude fields of LatLong are final :( I have solved the problem by first removing the layer and then adding it again but that results in some additional coordination logic. Is there some way I can actually move a Layer (Marker)?
Mapsforge treats layers to be anything like render layer, tile layer, map overlays like markers, etc.
The abstract class Layer defines the getPosition() method to return null, by default.
Some classes extended from it like TileLayer does not modify the method's behavior. But, some Layer's extended classes do modify it.
In your case, a map overlay type, the Marker class extends from Layer with a modified getPosition() method. The value of the private field Marker.this.latLong is not even final. It accepts a change to Marker.this.latLong via Marker.setLatLong() method.
Provided that the Layer object is really an instance of Marker, you can cast the object as Marker.

Quadtree on android maps utils

I'm developing a android application with google maps v2 that draw polygons on the google maps. But now i have to identify a click on a certain polygon and popup a window.
I found this useful library on github
This library has the method containsLocation implemented. This method receives a LatLng (from click on the map) and a List (the polygon). This is fine but if i have 1 million polygon in the map i cant iterate all and test if a certain LatLng belongs to a certain Polygon. I remember that i can use a quadtree to get more performance and this library also implements a quadtree but it uses point. What is the best way of doing this? May i have to reimplement this quadtree for a quadtree of LatLng ? Or in each click i have to convert this click to a point and search on a point quadtree?
Regards
you cannot use a Point- Quadtree, you need an Object-Quadtree for your Polygons. An object quadree uses the bounding box of the polygon or any object for adding into the tree.
you dont need to consider latLong, use x,y with x= longitude, and y = Latitude.
Consider reading Hanan Sammet: Foundations of multidimensional data structures.
I think you need to implement a quadtree that stores the polygons, then query the tree to see which polygon (if any) contains the LatLng. If you search around I'm sure you can find a decent implementation.

Categories

Resources