How to update my location after location turned on in flutter
I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.
Here is the example what I am working on
PS:
android dart flutter
add a comment |
I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.
Here is the example what I am working on
PS:
android dart flutter
add a comment |
I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.
Here is the example what I am working on
PS:
android dart flutter
I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.
Here is the example what I am working on
PS:
android dart flutter
android dart flutter
edited Nov 20 '18 at 6:09
Harsha Vardhan
asked Nov 19 '18 at 13:02
Harsha VardhanHarsha Vardhan
849
849
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Just subscribe to "onLocationChanged" Stream like in the example.
_location.onLocationChanged().listen((Map<String,double> result) {
var latitude = result["latitude"]; //This is called always when the location updates
var longitude = result["longitude"];
});
For showing a popup when the user has no location enabled use this:
try {
currentLocation = await location.getLocation;
} on PlatformException {
await showDialog<dynamic>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("No Location"),
content: Text(
"Please allow this App to use Location or turn on your GPS."),
actions: <Widget>[
FlatButton(
child: Text(
"Ok"
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
1
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375270%2fhow-to-update-my-location-after-location-turned-on-in-flutter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just subscribe to "onLocationChanged" Stream like in the example.
_location.onLocationChanged().listen((Map<String,double> result) {
var latitude = result["latitude"]; //This is called always when the location updates
var longitude = result["longitude"];
});
For showing a popup when the user has no location enabled use this:
try {
currentLocation = await location.getLocation;
} on PlatformException {
await showDialog<dynamic>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("No Location"),
content: Text(
"Please allow this App to use Location or turn on your GPS."),
actions: <Widget>[
FlatButton(
child: Text(
"Ok"
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
1
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
add a comment |
Just subscribe to "onLocationChanged" Stream like in the example.
_location.onLocationChanged().listen((Map<String,double> result) {
var latitude = result["latitude"]; //This is called always when the location updates
var longitude = result["longitude"];
});
For showing a popup when the user has no location enabled use this:
try {
currentLocation = await location.getLocation;
} on PlatformException {
await showDialog<dynamic>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("No Location"),
content: Text(
"Please allow this App to use Location or turn on your GPS."),
actions: <Widget>[
FlatButton(
child: Text(
"Ok"
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
1
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
add a comment |
Just subscribe to "onLocationChanged" Stream like in the example.
_location.onLocationChanged().listen((Map<String,double> result) {
var latitude = result["latitude"]; //This is called always when the location updates
var longitude = result["longitude"];
});
For showing a popup when the user has no location enabled use this:
try {
currentLocation = await location.getLocation;
} on PlatformException {
await showDialog<dynamic>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("No Location"),
content: Text(
"Please allow this App to use Location or turn on your GPS."),
actions: <Widget>[
FlatButton(
child: Text(
"Ok"
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
Just subscribe to "onLocationChanged" Stream like in the example.
_location.onLocationChanged().listen((Map<String,double> result) {
var latitude = result["latitude"]; //This is called always when the location updates
var longitude = result["longitude"];
});
For showing a popup when the user has no location enabled use this:
try {
currentLocation = await location.getLocation;
} on PlatformException {
await showDialog<dynamic>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("No Location"),
content: Text(
"Please allow this App to use Location or turn on your GPS."),
actions: <Widget>[
FlatButton(
child: Text(
"Ok"
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
answered Nov 19 '18 at 21:22
Niklas RaabNiklas Raab
8610
8610
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
1
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
add a comment |
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
1
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..
– Harsha Vardhan
Nov 20 '18 at 6:12
1
1
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)
– Niklas Raab
Nov 20 '18 at 12:51
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.
– Harsha Vardhan
Nov 20 '18 at 12:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375270%2fhow-to-update-my-location-after-location-turned-on-in-flutter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown