How do you get the corners of the screen as geographical coordinates for Google Maps using Flutter [duplicate] - flutter

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

Can you offset map.getCenter with padding?

In Mapbox you can use setCenter with an optional "padding" value which is useful for offsetting the map center if there are things such as overlays on part of the map. However getCenter does not seem to have the same padding option. This becomes an issue when I need to get the map center that matches the visual location of the offset center. Does anyone know of a way to get the center of the map with padding taken into account the same way that setCenter does?
The solution I found was to use Mapbox's unproject method. I first obtained the x/y screen coordinates of the offset map center, converted them to a mapbox Point object, and then used unproject to get that latitude and longitude at that location.
const point = new mapboxgl.Point(screenX, screenY);
const latLng = map.unproject(point);

Get LngLat form XY

I need to get lngLat coordinates from Mapbox map container center once the map is loaded and during user interaction with it. Tried to do on the basis of Get coordinates of the mouse pointer example but can't realize how to change e.point JSON coordinates from dynamic mouse cursor XY-coordinates to static XY-coordinates of map viewport center (outerWidht/2 and outerHeight/2).
Mapbox.js and MapboxGL both offer getCenter methods that return a map view's geographic center.
You can use various events such as moveend to update the center dynamically.

How to convert pixels into the map coordinate when calling easeTo() in mapbox

I am developing an interactive map in HTML+JavaScript using mapboxgl (0.33.1). When the user clicks a button (which is associated with a particular location in the map), I call easeTo(), which put that location in the center of the map.
window.map.easeTo({
center: item.loc
});
Because my application has some overlapping UI over the bottom half of the map, I actually want to put that location not in the center of the map, but in the center of the top half of the map (25% from the top).
I'd appreciate if somebody could give me a hint how achieve it. My app knows the exact sizes of the window in Pixel (and also the zoom level), but (I assume) I need to convert it into the map-coordinate (from pixel) to add an appropriate offset to the "center" parameter I pass to easyTo() function.
I think I found the answer. I just need to call the project() method -- which was very hard to discover!

SKTiled: specific tile position

I am using SKTiled.
The SKTileLayer.tileAt(0,0) function returns the tile at a CGPoint.
The SKTileLayer.pointForCoordinate(coord: CGPoint) does the same.
All I want is to get a Tile on the Grid (0,0) and not tiles on CGPoints. That would be the first Grid in the map. How can I get the tiles in that way?
Edit: tileAt(0,0) returns the first Grid but if I want to change the Player position to tileAt(0,0) it ist not the real position.
That's a great framework, you can use the method that returns a tile coordinate for a given point in the layer:
SKTileLayer.coordinateForPoint(<#T##TiledLayerObject#>)
You can find more details to the framework official documentation here
You can also get the tile following the autocompletion as:
As you can see it return a SKTile

Why does a pin placed at the same latitude and longitude in MKMapView differ from one in Google Maps?

I drop a pin in an MKMapView with longitude and latitude. When I place same longitude and latitude on google map the pin on both are slightly different.
I have a web/iPhone app that renders a map for positions sourced from the same database and haven't seen this issue. I would check your assumptions:
Are you truncating your values over the wire?
Are you rounding the position values differently on the two platforms?
Check the values you are passing into Google Maps and MapKit by logging them and comparing.
You can see from the following screenshots that the same latitude/longitude are rendered on the same position on the map:
Update
I tried the coordinates you mentioned in the comments and got the same position for both. You need to check your assumptions. The values that you are using on the web or on the device are not the values you think they are: