Initial native add markers implementation
Added addMarkers to jni.ccp, exposed addMarkers in MapView, updated example using this new method
This commit is contained in:
@@ -1078,6 +1078,19 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
return marker;
|
||||
}
|
||||
|
||||
public List<Marker> addMarkers(List<Marker> markers){
|
||||
long[] ids = mNativeMapView.addMarkers(markers);
|
||||
Marker m;
|
||||
int count = markers.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
m = markers.get(i);
|
||||
m.setId(ids[i]);
|
||||
m.setMapView(this);
|
||||
mAnnotations.add(m);
|
||||
}
|
||||
return markers;
|
||||
}
|
||||
|
||||
public Polyline addPolyline(PolylineOptions polylineOptions) {
|
||||
Polyline polyline = polylineOptions.getPolyline();
|
||||
long id = mNativeMapView.addPolyline(polyline);
|
||||
|
||||
@@ -333,6 +333,10 @@ class NativeMapView {
|
||||
return nativeAddMarker(mNativeMapViewPtr, marker);
|
||||
}
|
||||
|
||||
public long[] addMarkers(List<Marker> markers) {
|
||||
return nativeAddMarkers(mNativeMapViewPtr, markers);
|
||||
}
|
||||
|
||||
public long addPolyline(Polyline polyline) {
|
||||
return nativeAddPolyline(mNativeMapViewPtr, polyline);
|
||||
}
|
||||
@@ -561,6 +565,8 @@ class NativeMapView {
|
||||
|
||||
private native long nativeAddMarker(long nativeMapViewPtr, Marker marker);
|
||||
|
||||
private native long[] nativeAddMarkers(long nativeMapViewPtr, List<Marker> markers);
|
||||
|
||||
private native long nativeAddPolyline(long nativeMapViewPtr, Polyline polyline);
|
||||
|
||||
private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon);
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@@ -404,26 +405,34 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void addMarkers() {
|
||||
LatLng backLot = new LatLng(38.649441, -121.369064);
|
||||
final Marker marker = mMapView.addMarker(new MarkerOptions()
|
||||
.position(backLot)
|
||||
.title("Back Lot")
|
||||
.snippet("The back lot behind my house"));
|
||||
marker.setInfoWindowOnTouchListener(new View.OnTouchListener() {
|
||||
List<Marker> markerList = new ArrayList<>();
|
||||
|
||||
final Marker backLot = generateMarker("Back Lot", "The back lot behind my house", "default_marker", 38.649441, -121.369064);
|
||||
markerList.add(backLot);
|
||||
|
||||
final Marker cheeseRoom = generateMarker("Cheese Room", "The only air conditioned room on the property", "dog-park-15", 38.531577, -122.010646);
|
||||
markerList.add(cheeseRoom);
|
||||
|
||||
mMapView.addMarkers(markerList);
|
||||
|
||||
// need to call this after adding markers to map, click event hook into InfoWindow needs refactoring
|
||||
backLot.setInfoWindowOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
Toast.makeText(getApplicationContext(), "Custom Info Touch Listener!!", Toast.LENGTH_SHORT).show();
|
||||
marker.hideInfoWindow();
|
||||
backLot.hideInfoWindow();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LatLng cheeseRoom = new LatLng(38.531577,-122.010646);
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
.position(cheeseRoom)
|
||||
.sprite("dog-park-15")
|
||||
.title("Cheese Room")
|
||||
.snippet("The only air conditioned room on the property!"));
|
||||
private Marker generateMarker(String title, String snippet, String sprite, double lat, double lng){
|
||||
return new MarkerOptions()
|
||||
.position(new LatLng(lat,lng))
|
||||
.title(title)
|
||||
.sprite(sprite)
|
||||
.snippet(snippet)
|
||||
.getMarker();
|
||||
}
|
||||
|
||||
private void addPolyline() {
|
||||
|
||||
Reference in New Issue
Block a user