How to get bounds of visible map with flutter google_maps plugin? - google-maps

I'm trying to find out what is the bounding box of the visible part of google map in flutter's google maps plugin.
Is it possible to get it?
If not is it possible to calculate the bounding box based on zoom level and latitude, longitude of the map center?

That would be GoogleMapController.getVisibleRegion()

Be careful, GoogleMapController.getVisibleRegion() returns a LatLngBounds (a rectangle) and if your map has a tilt then it should not be a rectangle but a trapezoid!
The issue is in the plugin implementation where the returned result is computed only from latLngBounds field whereas it should be computed from farLeft, farRight, nearLeft, nearRight fields.
Reference: https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/model/VisibleRegion
So GoogleMapController.getVisibleRegion() is not accurate and can't be used if there's a tilt.
For reference, an issue has been created: https://github.com/flutter/flutter/issues/74888

Related

Get co-ordinates range while using leaflet

My application is in Angular 5. I am calling an API and get different data along with latitude & longitude. When I fetch these data, I am rendering markers on map based on lats & longs got from API using Leaflet I have created Marker Cluster to display markers in better way. You can imagine that markers displayed properly and its working.
Now I want to implement filter when I do ZoomIn & ZoomOut
I.e. When I zoomIn / zoomOut in map, it will cover some area right? I want those co-ordinates of covered area. By that range of co-ordinates I will execute API and get filtered results for that area only.
Any help?
Thanks in Advance
Use the getBounds() method on your Leaflet map object to obtain a LatLngBounds which describes the visible area of your map. You can use its values to feed your API query.
var bounds = mymap.getBounds()
Documentation at http://leafletjs.com/reference-1.3.0.html#map-methods-for-getting-map-state

How to zoom to the pointer in a google map

I have a google map in an iframe in which, I am passing the longitude and latitude.
What I want is,
I want show the map zoomed to the pointer corresponding to the longitude
and latitude given.
Fiddle
In the given fiddle, user have to scroll the map to right, to see the marker. Instead I want to show the marker to the user, when the map loads with better zoom.
I will have similar maps like this with different longitude and latitude in different pages. I want to apply this all those maps.
Your "ll" parameter is the one centering the map. If you give it the same value as the "q" parameter, your map will be centered on that point.
https://maps.google.co.in/maps?[]...q=38.89205,+1.35275&
[...]ll=38.89205,+1.35275&output=embed"
Here is a jsFiddle: http://jsfiddle.net/D4Y4r/
If you wish to zoom in, you can increase the value of the "z" parameter.
Quick edit: this page might provide you some insight on the URL parameters http://asnsblues.blogspot.in/2011/11/google-maps-query-string-parameters.html

google map zoom after directions

I am using google maps in order to give some directions from one point to another.
Although, I have set the zoom of the map to 15 the zoom changes after the response of the direction request in order probably to fit the directions into the map.
Does anyone nows how to keep the zoom constant at 15. and focus at the first point?
See the documentation for the DirectionsRenderer
preserveViewport: true
will prevent the DirectionsRenderer from changing the zoom.
To center the map on the first point use the map.setCenter function. You will need to parse the response from the directions service and create a google.maps.LatLng object for the first point.
This example shows one way to parse the response:
http://www.geocodezip.com/v3_directions_custom_iconsC.html
(you don't need everything, just the location of the point you want to center on)

How to find the boundary points with center and zoom level given?

The LatLngBounds function needs the corner points!
How to find the boundary points with center and zoom level given?
Is there Google API V3 which achieves this?
Or can this be done someway with the static maps?
Are you referring to the boundary points of the visible map? If so, you can use the getBounds method of the map object.
var llb = map.getBounds();
If you are using the geocoder, it returns a suggested viewort (that is a google.maps.LatLngBounds() object).
See this similar question:
Google Maps API zoom after setcenter
If you only have the center coordinates and the zoom, use them to initialize the map, listen for the bounds_changed event, then use the map.getBounds() function.
All of the above are described in the documentation

Google Maps API: setCenter from markers possible?

I have set of markers on Google map.
Is it possible to center the map in the way that all markers will be visible, and zoom level will also be auto adjusted?
Exactly the same way how Goolge Static Maps API does when you specify markers and do not specify center/zoom parameters (Implicit Positioning of the Map).
You can use var myBounds = google.maps.LatLngBounds() and basically extend all the points you have. Once you have all the points in the LatLngBounds() you can use your map.fitBounds(myBounds); and all marker should be visible and centered.
do you wish me to prototype a jsfiddle?