I know that using
const camera = map.getFreeCameraOptions();
const cameraPosition = camera._position.toLngLat();
I can get at cameraPosition the longitude and latitude from the camera, but what about the elevation/altitude?
What exactly is then, following the previous code:
const elevation = camera._elevation;
And why is always with the value undefined?
How can I get the correct altitude value?
Thanks in advance,
Joan.
Related
Using leaflet-topography I can get the elevation and slope data for a given point using Lat and Lang.
I got that data:
latlng: LatLng {lat: 40.74224422475555, lng: -73.76170149999999}
topography:
aspect: 279.4623222079068
elevation: 29.600000000000364
resolution: 57.847966427070006
slope: 1.2047623336529816
[[Prototype]]: Object
But is there a function out there to say:
With a given latitude and longitude I'll tell you if its on the street?
Thanks in advance!
If I pass latlnglastPosition to my widget, it's fine. I can see latitude and longitude and the value changes with zero lag as my camera position changes. However, using anything more than that causes crazy lag. It's practically unusable. Does anybody know what's causing this or if there's a better way of doing this? I'm trying to display latitude, longitude, altitude, distance from center versus current position in meters and miles. Here's the code:
void _onCameraMove(CameraPosition cameraPosition) async {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
lat = position.latitude;
lng = position.longitude;
alt = position.altitude;
_distancebetween = await Geolocator().distanceBetween(
_lastMapPosition.latitude, _lastMapPosition.longitude, lat, lng);
distancebetweenFinal = _distancebetween.toStringAsFixed(2);
distancebetweenFinalMiles = _distancebetween * (0.000621371);
_lastMapPosition = cameraPosition.target;
var latlnglastPosition = _lastMapPosition;
_currentZoom = cameraPosition.zoom;
setState(() {
latlnglastPosition;
distancebetweenFinal;
distancebetweenFinalMiles;
_distancebetween;
_lastMapPosition;
});
}
This is using Flutter Google Maps.
Edit: I removed the conversion from meters to miles. It didn't help. I don't think the altitude is having any impact. It's just going from current camera view position to my current position that's delaying everything. Is there perhaps a way to increase the frequency i receive location info? maybe that's hanging things up.... ?
Edit: or maybe I can use get last known position when a new location is not available? Not sure if that's the best way to handle this
Edit: I set lat = 34.0; lng = 34.0; and it's super fast now. However, it doesn't solve my problem. I need lat and lng to reflect my current position, and it seems i'm either restricted in pulling my current position or it's too costly to pull it as frequently as I need to. I don't know the best way to handle this... Any ideas are appreciated.
I got it (I think):
I replaced
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
with:
Position position = await Geolocator().getLastKnownPosition();
I think position.latitude and position.longitude were too costly before. So, I'm getting the last known position. If anyone knows a better way, please let me know.
I'm doing an app in my app. I'm using google maps flutter and I'm having an issue regarding scrolling. When I scroll the map I want to get the center points (long, lat) of the map that is if I scroll the map and stop at certain place it would grab the location points of center.
Can anyone suggest how to solve this issue? It can be very helpful Thank you in advance..
I would get the bounds of the screen, and then find the center of those bounds. If you have a GoogleMapController for the GoogleMap, just use a function like this:
getCenter() async {
LatLngBounds bounds = await mapsController.getVisibleRegion();
LatLng center = LatLng(
(bounds.northeast.latitude + bounds.southwest.latitude) / 2,
(bounds.northeast.longitude + bounds.southwest.longitude) / 2,
);
return center;
}
In the latest version of google maps flutter we can get the coordinates of location by passing in the screen coordinatinates,
// some code here
Size screen = MediaQuery.of(context).size;
// some code here
final coords = await mapController.getLatLng(ScreenCoordinate( x: screen.width/2, y:
screen.width/2));
I'm trying to put a marker at the center point of these coordinates. After calculating the bounds, I use getCenter() to give me the coordinates. But it returns "LatLng(-93.20448, 38.902475)" in longitude latitude direction, so using them in the marker doesn't work. It needs lat lon. I realize I'm not understanding something but what is it that I don't understand.
var bounds = L.latLngBounds([[-94.778092, 39.967458], [-91.630869, 39.967458], [-91.630869, 37.8374921], [-94.778092, 37.8374921], [-94.778092, 39.967458]]);
var middle = bounds.getCenter(); alert(middle); // LatLng(-93.20448, 38.902475)
var mk5 = new L.marker(new L.latLng( 38.902475, -93.20448 );
How can I get the longitude, and latitude of the current position showing on the mapView?
Thanks.
Current window position:
float latitude = myMapView.centerCoordinate.latitude;
float longitude = myMapView.centerCoordinate.longitude;
Current user position:
CLLocation userLocation = myMapView.userLocation.location;
float latitude = userLocation.coordinate.latitude;
float longitude = userLocation.coordinate.longitude;
The map userLocation will not be set right away, often it's better to just use Core Location if you need to get the users location. After all if the map is already using the GPS, using Core Location is kind of free in that you are using no more power than the map does - you can still have the map display the users location too.
That will also tell you things like "GPS is not working" or "GPS is not available" which you can't find out from Mapkit.