I am doing app on android using osmdroid. How I can get coordinates(top, bottom, left,right) of map which is shown on screen?
Thanx.
It is not completely clear what you're asking, but I think you're asking for the lat/lon bounding box.
BoundingBoxE6 boundingBox = mMapView.getProjection().getBoundingBox();
"I do it in onCreate if it important" => Yes, it is.
In fact, you cannot access to a correct mapview bounding box in onCreate.
This is "because the MapView's width and height is zero because it hasn't had onLayout called yet"
This is a (quite annoying) osmdroid issue, not fixed in v4.2.
In addition, when called in onCreate, setCenter is also not working properly in v4.2.
See more explanation and workarounds here: https://github.com/osmdroid/osmdroid/issues/22
In react-native I use the onRegionChangeComplete event (onRegionChangeComplete={e => properties.regionChange(e)}). This event returns the region of the MapView. So: {"latitude": 4.50751184289841, "latitudeDelta": 0.09999884159289252, "longitude": -75.67515761717539, "longitudeDelta": 0.06322002503726765}
So, if you need to calculate a polygon with the screen area, you should do the following:
regionChange = (e) => {
areaLoadData = [
{
latitude: e.latitude + e.latitudeDelta,
longitude: e.longitude - e.longitudeDelta
},
{
latitude: e.latitude + e.latitudeDelta,
longitude: e.longitude + e.longitudeDelta
},
{
latitude: e.latitude - e.latitudeDelta,
longitude: e.longitude + e.longitudeDelta
},
{
latitude: e.latitude - e.latitudeDelta,
longitude: e.longitude - e.longitudeDelta
},
]
}
Related
I have seen solutions including using onDragEnd or this method
void _updatePosition(CameraPosition _position) {
Position newMarkerPosition = Position(
latitude: _position.target.latitude,
longitude: _position.target.longitude);
Marker marker = markers["1"];
setState(() {
markers["1"] = marker.copyWith(
positionParam: LatLng(newMarkerPosition.latitude, newMarkerPosition.longitude));
});
}
it shows on class Position : Undefined class 'Position',
and onDragEnd not available
What is the reason and how can I get position from marker ?
If the IDE/Flutter says "Position" is "Undefined", Please check you have imported the "Geolocator" package. It's implemented in this package.
Add this to pubspec.yaml dependecies:
geolocator: ^6.1.7
and make sure it is imported in the .dart file you're working on. :)
I could really use some help improving the accuracy of the Geofencing feature. If you look at the following screenshots you can see my location and the location of circle and marker which share the same latLng coordiantes and radius as my geofence.
Link to the image
If I run the following lines within the app.js file:
const taskName = "front_door";
const latLng = { latitude: -37.820711, longitude: 144.994264 };
const radius = 5;
Permissions.askAsync(Permissions.LOCATION);
Location.startGeofencingAsync(taskName, [
{
...latLng,
radius
}
]);
TaskManager.defineTask(taskName, task => {
if (task.data.eventType === Location.GeofencingEventType.Enter) {
console.log("entered");
}
console.log(task.data.region.state);
return;
});
Which is returning entered and 1 (explanation).
Given my current location being outside of the geofence I would expect entered to fire only once I had inside of the geofence and task.data.region.state to equal 2 (explanation).
If I change:
const latLng = { latitude: -37.820711, longitude: 144.994264 };
To:
const latLng = { latitude: -37, longitude: 144 };
The geofence is far enough away that entered is never output and the task.data.region.state equals 2.
This leads me to believe that the issue is related to the accuracy set of Location however, I cannot find a way to increase the accuracy when using the startGeofencingAsync method.
If I was not using geofencing I would do something like this:
Location.startLocationUpdatesAsync(taskName, {
accuracy: Location.Accuracy.Highest
});
But I can't see how to access the options object when using Location.startGeofencingAsync(taskName, regions)
If you know how to achieve this please do let me know as I am pulling my hair out over it! Thanks in advance :)
I'm working on a project and I'm using some old google maps stuff. It requires longitude and latitude gps coordinates to get the location of a hospital for example.
I can't find a way to retrieve that info in this format 'lng,lat'
For example: (34.417514, 8.7518123)
The only thing the new google maps has is plus codes (used by https://plus.codes/) which they use as the location coordinates.
Can you guys help me find out a way to convert them to lng lat format or a way to retrieve the lng and lat from Google Maps website directly.
Or an alternative by saving my geolocation in a plus codes format in android studio (in a database of course) instead of using lat lng
https://www.up-00.com/i/00125/m4kadq6c7aeb.png
You can convert Plus Codes into lat/lng format via Plus codes API. If you have full (8-digits before "+" character, e.g. 8F6CCQCW+2F for your location) Plus Code, you can locally (without any internet request) use OpenLocationCode.decode() method this way:
...
OpenLocationCode olc = new OpenLocationCode("8F6CCQCW+2F");
Log.d(TAG, "Lat = " + olc.decode().getCenterLatitude() + " Lng = " + olc.decode().getCenterLongitude());
...
If you have short Plus Code (less than 8 digits before "+" character, e.g. CCQCW+2F Gafsa for your location, Gafsa is the area and it's used instead of using the full plus code) you can use HttpURLConnection with
`https://plus.codes/api?address=CCQCW%2B2F Gafsa&key=YOUR_GEOCODING_API_KEY`
(%2B is for the for + symbol)
(NB! you need Geocoding API Key for geocode Gafsa part, which is the area, you need an area with a short plus code)
and get location.lat and location.lng tags from its JSON response:
{
"plus_code": {
"global_code": "8F6CCQJG+",
"geometry": {
"bounds": {
"northeast": {
"lat": 34.432500000000005,
"lng": 8.777500000000003
},
"southwest": {
"lat": 34.43000000000001,
"lng": 8.775000000000006
}
},
"location": {
"lat": 34.431250000000006,
"lng": 8.776250000000005
}
},
"locality": {}
},
"status": "OK"
}
For "alternative" (saving my geolocation in a plus codes format) you can (fully local) use encode() method of OpenLocationCode class:
OpenLocationCode.encode(34.43125, 8.77625)
Python solution:
>>> import openlocationcode
>>> openlocationcode.decode('8F6CCQCW+2F')
[34.42, 8.796125, 34.420125, 8.79625, 34.4200625, 8.7961875, 10]
Python implementation
from openlocationcode import openlocationcode as olc
olc.decode("8F6CCQCW+2F")
Output:
[34.42, 8.796125, 34.420125, 8.79625, 34.4200625, 8.7961875, 10]
How to store values in firebase from android like this:
polyline : [
{
latitude: 39.8282,
longitude: -98.5795
},
{
latitude: 37.772,
longitude: -122.214
},
{
latitude: 21.291,
longitude: -157.821
}}
so it can be used by agm/core's polyline. Firebase doesn't accept arrays and it seems like the only way to pass the polyline directive a set of coordinates and then iterate through it to draw out the polyline path would be as an array. Otherwise, I guess, I would have to pass individual latlong points to angular and create an array this way but I would prefer not doing it this way.
I have records on the table list contains data that has latitude & longitude on the listing widow. When I click on each row, it passes to the detail window that display the mapview and its annotation of that record.
I zoom in & out, moved to different area and I clicked "back" button to go back to the record list.
Then, I selected on the different record to see the map on the detail window again, when I'm on the detail window suddenly I clicked on the map, there, it alerts me an error message which did not mention about the specific issues.
Here is my code:
self.listingAnnotation = Titanium.Map.createAnnotation({
pincolor: Titanium.Map.ANNOTATION_RED,
latitude: latitude,
longitude: longitude,
animate: true
});
self.region = {
latitude: latitude,
longitude: longitude
};
if(!self._mapview){
self._mapview = Titanium.Map.createView({
top: 130,
bottom: 0,
animate:true,
mapType: Titanium.Map.STANDARD_TYPE,
region: {latitude: latitude, longitude: longitude},
annotations: [self.listingAnnotation]
});
}
else{
self._mapview.removeAllAnnotations();
self._mapview.setLocation(self.region);
self._mapview.addAnnotation(self.listingAnnotation);
}
self._listingDetailWindow.add(self._mapview);