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. :)
Related
I want to add just one marker when tap on map and return the value of position it stands on
how can I do this ?
NOTE : GoogleMap doesn't have onTap
You can try this library for google map https://pub.dev/packages/google_maps_flutter and also it has on tap on the marker onTap.
Marker(
markerId: MarkerId("id"), // a string for marker unique id
position: LatLng(lat, long), // lat and long doubles
onTap: () {
//this is what you're looking for!
}
)
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 am creating an Android App , an Uber Clone. In this I am using Firebase to list the rides created by the user.
The Ride stored in the following format .
{
"category" : "NUVO",
"driverids" : "",
"drop_lat" : "40.7127753",
"drop_long" : "-74.0059728",
"estdate" : "Wed#Feb#28th",
"estmile" : "4.19",
"esttime" : "01:02#PM",
"esttotalfare" : "4.61",
"fareest" : "1.1",
"g" : "t9z83wv46x",
"l" : [ 40.674426, -73.944033 ],
"notes" : "Gv",
"orgin_lat" : "145 Brooklyn Ave, Brooklyn, NY 11213, USA%20New York, NY, USA",
"request_id" : "5a75579740d166e95b8b4567",
"requested_category" : "FAM_SUV",
"rider_id" : "5a507bf340d16660288b4567",
"status" : 1,
"trip_id" : 0
}
Now I am Using GeoFire's GeoQuery's queryAtLocation to pick all rides with in 5 KMs from his current location.
The query uses the lat & lang from the field "l" and compare it with the current location lat & lang of the driver.
If the list's lat & lang is within 5 KMs , it will return the key , that is the parent name of the child "l".
Now I am currently in India. I use Lockito App to fix a Mock GPS location in India. After that I create a Ride within 5 KMs radius.
Now , the ride successfully listed in the drivers list. No Problem.
My Issue
But When I fix a mock GPS location in USA , this flow not working. I fixed the driver location on Brookyln Childeren's Museum and also created a ride on the same museum. But GeoQuery not calling onKeyEntered . It simply exists after calling GeoQueryReady function .
I check my current Lat & Lang from the app and it returns as 40.67434763453142,-73.94402358680964. I checked this against the lat&lang on field "l" .(refer above JSON). Both pointing to same location.
But GeoQuery failed to retrieve it
My Question
Why this issue happening ?. If I use India's locations. Geoquery works perfectly .
But why it failing in USA.
You may tell ,"There will be an issue in lockito". But Lockito returning correct location lat lang . I checked it in Logcat. And , if there is a issue in Lockitto then How it working in India.
Here My GeoQoery Code :
try {
showDialog();
double nearByDistanceRadius = 5.00d;
com.firebase.geofire.GeoFire geoFire = new com.firebase.geofire.GeoFire(FirebaseDatabase.getInstance().getReference().child(childtype));
final com.firebase.geofire.GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), nearByDistanceRadius);
geoQueryEventListener=new GeoQueryEventListener() {
#Override
public void onKeyEntered(final String key, GeoLocation location) {
Toast.makeText (getApplicationContext(), "The key is = ",Toast.LENGTH_LONG).show();
}
#Override
public void onKeyExited(final String key) {
System.out.println("ON KEYEXITED"+key);
}
#Override
public void onKeyMoved(String key, GeoLocation location) {
System.out.println("ON KEYMOVED"+key);
}
#Override
public void onGeoQueryReady() {
System.out.println("ON KEYQUERYREADY");
#Override
public void onGeoQueryError(DatabaseError error) {
System.out.println("ON KEYERROR"+error);
}
};
geoQuery.addGeoQueryEventListener(geoQueryEventListener);
} catch (Exception e) {
e.printStackTrace();
}
Above , except onGeoQueryReady , no method called if I use USA. But it's
working in India. Can anyone tell me why that is the case?
This maybe long gone n dusted but perhaps can help others.
Since u mention its mock GPS coordinates. and u probably manually entered them.
GeoFire uses a special g: "code" (10 digit code) which is area wise / city wise
if you use the same g code in the same city / country (India in ur case) it will work fine !
However,if you use the same code in another country , geoQuery will fail. To make it work. u need to add one line in your code
geoFire.SetLocation() and someone in USA needs to run that code once only. geoFire will save a special key in g: "" Location. After you have the key you can remove that line from your app.
You can use that key generated by geoFire to manually enter as many locations as you want in USA and geoQuery will always work on that !!! Make sure you use the same pattern as geoFire does.
g:
l:
0:
1:
It took a while but I figured. It's that buggy geofire dependency. Downgrade from 3.0.0 to 2.3.1 solved it.
I have a list of addresses and I want to mark this places all in google maps(nearly 1k), getting maybe its cordinates to save them.
Actually I am not programming an app, but I know both lenguages (Android and PHP) and I think it is possible to do this with both. Any idea ? Thank in advance!
Have you tried the google maps api?
https://developers.google.com/maps/documentation/geocoding/intro
https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
This is what you are looking for I think.
EDIT: to mark stars on map
// In the following example, markers appear when the user clicks on the map.
// Each marker is labeled with a single alphabetical character.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var labelIndex = 0;
function initialize() {
var bangalore = { lat: 12.97, lng: 77.59 };
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: bangalore
});
// This event listener calls addMarker() when the map is clicked.
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng, map);
});
// Add a marker at the center of the map.
addMarker(bangalore, map);
}
// Adds a marker to the map.
function addMarker(location, map) {
// Add the marker at the clicked location, and add the next-available label
// from the array of alphabetical characters.
var marker = new google.maps.Marker({
position: location,
label: labels[labelIndex++ % labels.length],
map: map
});
}
I am using Google Maps v2 in my application. When the user pans or zooms on the screen I would like to get the area of the map based on which I want to fetch the POI only in the screen view part.
I went through the documentation but could not find any help.
You need to use Projection and VisibleRegion classes in order to get visible LatLng region.
So your code would look something like:
LatLngBounds curScreen = googleMap.getProjection()
.getVisibleRegion().latLngBounds;
In Android(Kotlin) you can find LatLng this way, in every time zoom or. gesture detect
private var mMap: GoogleMap? = null
..........
mMap?.setOnCameraMoveStartedListener { reasonCode ->
if (reasonCode == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
val curScreen: LatLngBounds = mMap!!.getProjection().getVisibleRegion().latLngBounds
var northeast=curScreen.northeast
var southwest=curScreen.southwest
var center=curScreen.center
Log.v("northeast LatLng","-:"+northeast)
Log.v("southwest LatLng","-:"+southwest)
Log.v("center LatLng","-:"+center)
}
}