I have tryied Like [with 2 Lat Long Details]
final LatLng latlong = new LatLng(lat,lng);
final LatLng latlongcr = new LatLng(currentlat,currentlong);
mapView.addMarker(new MarkerOptions().position(latlongcr).title("Here You Are"));
mapView.addMarker(new MarkerOptions().position(latlong).title(addr));
mapView.moveCamera(CameraUpdateFactory.newLatLngZoom(latlong, 20));
mapView.moveCamera(CameraUpdateFactory.newLatLngZoom(latlongcr, 20));
mapView.animateCamera(CameraUpdateFactory.zoomTo(20), 2000, null);
But Get Only One Marker. want to show 2 marker Mapview working fine
Try using LatLngBounds.Builder:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(latlongcr);
builder.include(latlong);
LatLngBounds bounds = builder.build();
mapView.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 20));
Related
In google maps I want to fix my camera to a particular country. I don't need whole worlds Mercator projection. So I need to set LatLngBounds in my google maps. How can I find LatLngBounds of a particular region?
Here is my code but it's not setting LatLngBounds as my expectation set's constraints on right side.
LatLng v1= new LatLng(24.044982389517603,89.75482430309057);
LatLng v2 = new LatLng(22.309956868003045,91.20187237858772);
LatLngBounds BANGLADESH = new LatLngBounds(
v2,v1
);
mMap.setLatLngBoundsForCameraTarget(BANGLADESH);
You can get country boundaries once from openstreetmap.org like described in this article of PÄ“teris Å…ikiforovs or by http://polygons.openstreetmap.fr/get_poly.py?id=184640¶ms=0 and add it as polygon points find LatLngBounds like you do it:
...
Builder builder = new LatLngBounds.Builder();
for(int i = 0 ; i < N_POINTS; i++) {
builder.include(new LatLng(lat, lng));
}
LatLngBounds BANGLADESH = new LatLngBounds = builder.build();
int padding = 15; // offset from edges of the map in pixels
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(BANGLADESH, padding);
mMap.moveCamera(cameraUpdate );
...
I have two points of LatLng coordinates. And I draw a polyline based on that coordinates . How can I fit that polyline drawing on top of the screen with zoomed out to view full line? Is LatLngBounds.Builder the correct solution for that?
these is my code i am using now
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//latlong and latlong1 are my two points.
String[] latlong = pickUp.split(",");
LatLng location = new LatLng(Double.parseDouble(latlong[0]), Double.parseDouble(latlong[1]));
String[] latlong1 = destination.split(",");
LatLng location1 = new LatLng(Double.parseDouble(latlong1[0]), Double.parseDouble(latlong1[1]));
builder.include(location);
builder.include(location1);
LatLngBounds bounds = builder.build();
int padding = 40;
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mMap.animateCamera(cu);
I have cordinates from json and I want to show them all in map , here it shows markers but some of them not appear I want to set zoom to fit appearing all markers in map ,how can I do it ?
JSONArray postsJson = success.getJSONArray("now");
for (int i = 0; i < postsJson.length(); i++) {
Order_Start_Lat=c.getDouble("order_start_latitude");
Order_Start_Lng=c.getDouble("order_start_longitude");
MarkerOptions m = new MarkerOptions()
.title(client_name)
.position(new LatLng(Order_Start_Lat,Order_Start_Lng));
map.addMarker(m);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(Order_Start_Lat,Order_Start_Lng));
LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 20));
You should use the CameraUpdate class to do (probably) all programmatic map movements.
To do this, first calculate the bounds of all the markers like so:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker marker : markers) {
builder.include(marker.getPosition());
}
LatLngBounds bounds = builder.build();
Then obtain a movement description object by using the factory: CameraUpdateFactory:
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
Finally move the map:
googleMap.moveCamera(cu);
I am working on google map where i am using google map api to add multiple markers on the google map for ATMs .It means i have multiple markers corresponding to ATMs in my google map.When i click on a marker,a polyline is drawn between my current location and marker.When i click on another marker ,a new polyline is drawn but the previous one is not deleted.Please find below my code:
#Override
protected void onPostExecute(String parseData) {
super.onPostExecute(parseData);
dialog.dismiss();
//map.clear();
ArrayList<LatLng> allpooints = CommonUtility.decodePoly(parseData);
if(prevPolyLine!=null) {
prevPolyLine.remove();
//map.clear();
Log.e(" ","polyline");
PolylineOptions options = new PolylineOptions();
options.width(7);
options.color(Color.BLUE);
options.geodesic(true);
options.visible(true);
for (LatLng temp : allpooints) {
options.add(temp);
}
prevPolyLine = map.addPolyline(options);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng latLng : allpooints) {
builder.include(latLng);
}
final LatLngBounds bounds = builder.build();
//BOUND_PADDING is an int to specify padding of bound.. try 100.
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20);
map.animateCamera(cu);
}else{
Log.e("polylineTAG","----------------------");
PolylineOptions options = new PolylineOptions();
options.width(7);
options.color(Color.BLUE);
options.geodesic(true);
options.visible(true);
for (LatLng temp : allpooints) {
options.add(temp);
}
prevPolyLine = map.addPolyline(options);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng latLng : allpooints) {
builder.include(latLng);
}
final LatLngBounds bounds = builder.build();
//BOUND_PADDING is an int to specify padding of bound.. try 100.
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20);
map.animateCamera(cu);
}
}
Screenshot
Please help me to fix the issue.I want to remove polyline drawn between my current location and previous marker,when i click on new marker in the map.
Can someone explain how I can use the Google maps API in my project?
Cause I want to draw a marker on the map while moving the map with my finger.
But I don't know how to achieve this.
I am using the following code:
camCenter = mMap.getCameraPosition().target;
if (camCenter != null && camCenter != camCenterFirst) {
CameraUpdate center =
CameraUpdateFactory.newLatLng(new LatLng(camCenter.latitude,camCenter.longitude));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(16);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
camCenterFirst = camCenter;
}
First you have to add a marker to your Map like this:
LatLng pos = new LatLng(53.557115, 10.023159);
Marker m = mMap.addMarker(new MarkerOptions().position(pos).title(""));
The example above, gives you a default position of the marker.
Then you can change the position of the marker with following command:
m.setPosition(new LatLng(latitude,longitude));
Hope this helps!
public void showOnMap(Double lat,Double lng,String place)
MarkerOptions marker = new MarkerOptions().position(new LatLng(lat,
lng)).title(""+place);
mMap.addMarker(marker);
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(lat, lng)).zoom(12).build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
double radiusInMeters = 5000.0;
int strokeColor = 0xffff0000; //red outline
int shadeColor = 0x44ff0000; //opaque red fill
CircleOptions circleOptions = new CircleOptions().center(new LatLng(lat,lng)).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8);
mMap.addCircle(circleOptions);
}
I have done a complete demo of what you are looking for,
Check this Github code
https://github.com/cseshaiban/GeoApp