How to show boundary in map v2 on opening map? - android

I have a boundary on map and i saved all those tapped co-ordinates of that boundary. I want to show that complete boundary when i opens the map. How can i achieve it? I tried it by changing the (zoom level) camera position but not getting.
Actually my intention is how to pass more than 5 co-ordinates to map so that it shows all those passed co-ordinates on screen (fix the passed co-ordinates in mobile screen and show it when open it).

I tried this but not working perfectly, i want to change the zoom level dynamically based on passed co-ordinates.
private void showBoundary() {
final LatLng hmt = new LatLng(17.42214430,78.5483395);
final LatLng tharnaka = new LatLng(17.426542300,78.53627059999997);
final LatLng habsiguda = new LatLng(17.40681270000,78.547629599999940);
final LatLng uppal = new LatLng(17.401809200,78.56018919999997);
LatLngBounds bounds = new LatLngBounds.Builder()
.include(hmt)
.include(tharnaka)
.include(habsiguda)
.include(uppal)
.build();
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds,50));
}
Actually my intention is how to pass more than 5 co-ordinates to map so that it shows all those passed co-ordinates on screen (fix the passed co-ordinates in mobile screen and show it when open it).

Related

Android Google Map: Dynamic Map zoom Level vs Static Map Zoom Level

I have to use Google dynamic map to search a location, scroll, zoom, etc and then take a screenshot of the map. Due to license restriction, I cannot take a screenshot (GMap.Snapshot(this)). So it was decided to download an image from google static map
When the user wants to switch from map dynamic mode to static map, he clicks a button and I take center latitude and longitude, zoom level and map size (it's xamarin android)
{
CenterLatLng = new double[] { GMap.CameraPosition.Target.Latitude, GMap.CameraPosition.Target.Longitude },
ZoomLevel = (int)GMap.CameraPosition.Zoom,
Type = GMap.MapType,
MapSize = new int[] { MapFragment.View.MeasuredWidth, MapFragment.View.MeasuredHeight }
};
with this parameters i will try to download a static map
int scale = 2;
var url = $"https://maps.googleapis.com/maps/api/staticmap?center={myobject.CenterLatLng[0]},{myobject.CenterLatLng[1]}&zoom={myobject.ZoomLevel}&size={myobject.MapSize[0] / scale}x{myobject.MapSize[1] / scale}&scale={scale}&maptype=satellite&format=png&key=xxxxxxxx";
but downloaded static map seems to have a different zoom from dynamic Map
Here a screenshot of the Dynamic Map displayed before than switching to Static map
Here a screenshot of the Static Map displayed after
how can I fix that difference between dynamic map zoom and static map zoom?
how can I fix that difference between dynamic map zoom and static map zoom?
I think the issue is caused by the size you set in the url size={myobject.MapSize[0] / scale}x{myobject.MapSize[1] / scale}.
You could create a new variable to divide the MapSize instead of using scale to change the size.

Is it possible to check if a point is inside a polygon from geojson?

I have a geojson with some polygons, added it as a source and created a layer to show those features on the mapbox map.
Since I am using this method: (Edit from the sample souce: MapboxGLAndroidSDKTestApp)
final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
List<Feature> fList = mapboxMap.queryRenderedFeatures(pixel, "polygons");
for(Feature feature:fList){
Log.d(TAG,"FeatureInfo: "+feature.toJson());
}
I can check if the marker is inside one of those polygons by passing the marker position to it.
But when I move my camera far away to the marker, the polygon is not rendered and the checker is not work anymore.
So my question is, is there any way to check if the marker is inside the polygon, which no matter where is my camera pointing at?
To check a point whether lies or not inside a polygon on mapbox
can use turf.js library http://turfjs.org/
This is the way in which you don't need to plot point or polygon on the mapbox(without plotting).
var point = turf.point([-75.343, 39.984]);
// here first is lng and then lat
var polygon = turf.polygon([[
[-2.275543, 53.464547],
[-2.275543, 53.489271],
[-2.215118, 53.489271],
[-2.215118, 53.464547],
[-2.275543, 53.464547]
]], { name: 'poly1'});
// here first is lng and then lat
now you can use inside method from turf lib
i.e turf.inside(point, polygon); // return boolean True/False
Use TurfJoins.inside(yourPoint, yourPolygon)

Snapshot google maps api v2 between two points

i'm doing an app in android studio and what i'm trying to do is a route tracking app, the user touch a play button and he can see in the map a marker with his route being drawn by polylines.
I did that already but i want your help because when the user touch the stop button i want to take a Snapshot of the complete route (including the start point and the end point) and i don't know how to do that, because if the route is long and the zoom is close to the map then the starting point isn't going to show...
I hope you understand and could help me! :)
Sorry for my English, I use this example in my code to zoom all the markers, its simple i use a cycle for add the LatLng and zoom all.. with CameraUpdateFactory.newLatLngBounds(bounds_latandlog,padding);, and you take the Snapshot...
LatLngBounds.Builder builder = new LatLngBounds.Builder();
///this is an example
LatLng latLng;// create var LatLng
for(int i=0;i<=10;i++)// you will do a type of cycle, tu add lat and long
{
latLng = new LatLng(lat, lon);// in this line put you lat and long
builder.include(latLng); //add latlng to builder
}
//create a lat long bounds
LatLngBounds bounds = builder.build();
//create a padding of the points and the camera of the map
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
//finally move the camera, to zoom all the polylines
/// move the camera
googleMap.moveCamera(cu);
//or animate the camera...
googleMap.animateCamera(cu);
This is the link, for more information
Android map v2 zoom to show all the markers
if you see some error, or you have a better syntaxis, please explane me, I want to learn it.

MapController, OSMdroid, zoomToSpan() freezes application

I use OSMdroid to display an offline map. The MapView is placed inside a Fragment. I would like to zoom the map to cover two points (top_left, bottom_right). Currently when I call zoomToSpan() in onViewCreated() the app freezes. I have tried using BoundingBoxE6 and latitude, longitude span but nothing changes.
BoundingBoxE6 bb = new BoundingBoxE6(
LocationConstants.TOP_LEFT_LATITUDE,
LocationConstants.TOP_LEFT_LONGITUDE,
LocationConstants.BOTTOM_RIGHT_LATITUDE,
LocationConstants.BOTTOM_RIGHT_LONGITUDE);
or
int latitudeSpan = (int) Math.abs(LocationConstants.TOP_LEFT_LATITUDE*1E6 - LocationConstants.BOTTOM_RIGHT_LATITUDE*1E6);
int longitudeSpan = (int) Math.abs(LocationConstants.TOP_LEFT_LONGITUDE*1E6 - LocationConstants.BOTTOM_RIGHT_LONGITUDE*1E6);
give the same results.

code to add markers to map using android google maps v2

I have lat&long values from database.how to display markers based on lat &long values using android google map api v2.In original android google maps,we display markers based on concept itemoverlay. In v2,I dont know how to display markers.
dbAdapter.open();
Cursor points = dbAdapter.clustercall(Btmlft_latitude, toprgt_latitude,
Btmlft_longitude, toprgt_longitude, gridsize1);
int c = points.getCount();
Log.d("count of points", "" + c);
if (points != null) {
if (points.moveToFirst()) {
do {
int latitude = (int) (points.getFloat(points
.getColumnIndex("LATITUDE")) * 1E6);
int longitude = (int) (points.getFloat(points
.getColumnIndex("LONGITUDE")) * 1E6);
mapView.addMarker(new MarkerOptions().position(
new LatLng(latitude, longitude)).icon(
BitmapDescriptorFactory.defaultMarker()));
} while (points.moveToNext());
}
}
points.close();
dbAdapter.close();
That is mycode.I am getting lat&long values from database,but how to add markers based on lat &long values to map.
I read the android google maps api v2.In that have only give statically added data of markers
Use the Marker Class
An icon placed at a particular point on the map's surface. A marker icon is drawn oriented against the device's screen rather than the map's surface; i.e., it will not necessarily change orientation due to map rotations, tilting, or zooming.
A marker has the following properties:
Anchor
The point on the image that will be placed at the LatLng position of the marker. This defaults to 50% from the left of the image and at the bottom of the image.
Position
The LatLng value for the marker's position on the map. You can change this value at any time if you want to move the marker.
Title
A text string that's displayed in an info window when the user taps the marker. You can change this value at any time.
Snippet
Additional text that's displayed below the title. You can change this value at any time.
Icon
A bitmap that's displayed for the marker. If the icon is left unset, a default icon is displayed. You can specify an alternative coloring of the default icon using defaultMarker(float). You can't change the icon once you've created the marker.
Drag Status
If you want to allow the user to drag the marker, set this property to true. You can change this value at any time. The default is true.
Visibility
By default, the marker is visible. To make the marker invisible, set this property to false. You can change this value at any time.
GoogleMap map = ... // get a map.
// Add a marker at San Francisco.
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183))
.title("San Francisco")
.snippet("Population: 776733"));
You have to use the method GoogleMap.addMarker(MarkerOptions);
I've explained this in a tutorial on my blog:
http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html
On this blog, you'll find some more posts concerning the new Maps API:
Move the map to current or some location
Create the custom InfoWindow
Associate geodata or objects to a marker
I'm guessing the issue is that you are multiplying your latitude/longitude values by 1E6 instead of dividing them by 1E6. If your stored values came from GeoPoints, that might be your issue. Otherwise, the way you are adding the Markers is fine and should work.
i.e. the lat/lng values you pass to new LatLng() should look like 45.4,-95.5 NOT 45400000,-95500000
Check out the following code:
//mMap is a GoogleMap and point is a GeoPoint
this.mMap.addMarker(getMarker(point, drawableId))
...
public MarkerOptions getMarker(GeoPoint point, int drawableId)
{
return new MarkerOptions()
.position(new LatLng(point.getLatitudeE6() / 1000000.0, point.getLongitudeE6() / 1000000.0))
.icon(BitmapDescriptorFactory.fromResource(drawableId));
}

Categories

Resources