in my Xamarin.Forms App I have an Page which indicates an GoogleMap.
Everything is working perfect, but when I click on an InfowWindow from a pin, i cant open a new detailpage. The App hangs and I can do nothing with the App. I get no error message.
But its working in iOS.
Heres the Code:
private void MapObjekt_InfoWindowClicked(object sender, InfoWindowClickedEventArgs e)
{
App.locator.StopListeningAsync();
App.locator.PositionChanged -= Locator_PositionChanged;
objektliste detailPage = new objektliste();
App.mdp.Detail = detailPage;
}
Whats my fault ?
Problem was, that I have to open the Page in the Mainthread like this:
Device.BeginInvokeOnMainThread(() => { App.mdp.Detail = detailPage; });
Related
Here is my initializeCamera code :
initializeCamera() async {
try {
final cameras = await availableCameras();
final firstCamera = cameras.first;
ContextManager.camera = firstCamera;
setState(() {
cameraAuthorized = true;
ContextManager.cameraAuthorized = cameraAuthorized;
});
} catch(e) {
ContextManager.camera = null;
setState(() {
cameraAuthorized = false;
ContextManager.cameraAuthorized = cameraAuthorized;
});
print(e);
}
}
Here is my initState code where I call the initializeCamera function and after that initialize the CameraController :
#override
void initState() {
super.initState();
initializeCamera().then((value) {
if (ContextManager.camera != null) {
setState(() {
_controller = CameraController(
ContextManager.camera,
ResolutionPreset.medium,
);
_initializeControllerFuture = _controller.initialize();
});
}
});
}
When I am running the code with flutter web from my computer browser I get this popup from my initializeCamera step :
When I click "allow" the rest of the code which is called in the then()
and especially _controller.initialize(), which initialize my camera on the device, is executed and the camera starts working. When I click "deny" another part of the code that I customed is run to display a message on the screen, in other words everything works fine.
When I'm running on the Android Emulator everything from my initializeCamera() function to _controller.initialize() is run without interruption until I get this popup :
Whether I choose "while using the app" or "only this time" the camera starts working and everything is ok. But when I click "deny" the app throws a CameraException.
I tried to wrap this line (which is causing the issue) :
_initializeControllerFuture = _controller.initialize()
in try/catch, and also specifying the name of the exception, but nothing worked.
What I don't get here, is that _controller.initialize() function is called before the popup show in the emulator, so the camera is initialized on the device before we can actually choose to deny/allow it.
While on the computer you actually get to choose whether you deny/allow the camera before the _controller.initialize() function is executed, which make perfect sense to me.
The ways it works on the emulator doesn't make any sense for me, if someone more knowledgeable could enlighten me, thanks.
I have a problem with loading a second page. If I debug the whole project, Google Maps do not show, but if I debug with other XML. I mean I add label without anything, everything works fine. If I debug the project on a second page, Google Maps work.
Second page:
public Mapciorek()
{
InitializeComponent();
MyMapa.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(Convert.ToDouble(13.0291), Convert.ToDouble(80.2083)), Distance.FromMiles(0.3)));
}
XML:
<ScrollView>
<maps:Map
x:Name="MyMapa"
IsShowingUser="true"
MapType="Hybrid" HasZoomEnabled="True" />
</ScrollView>
App:
MainPage = new NavigationPage(new MainPage());
First page (main page):
async private void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Mapciorek());
}
i am using ion-google-place directive in my ionic project and when i run it in the ripple I can see that this directive works as expected, however when i deploy it on my Android phone the search bar comes up but when i type no drop down is shown.
I tried to debug the code and can see the issue to be around the following code:
var geocoder = new google.maps.Geocoder();
geocoder.geocode(req, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
scope.$apply(function () {
scope.locations = results;
});
} else {
// #TODO: Figure out what to do when the geocoding fails
console.log("error getting google place...");
}
});
the callback function is never called when running within the android phone, however from ripple its working.
Any ideas as to what I may be missing ?
EDIT 1:
I created a Blank Cordova project and added the refrences to angular and google map. Then added a button and added a ng-onclick to that button as below
$scope.onButtonClick = function () {
var api = new google.maps.places.AutocompleteService();
api.getPlacePredictions({ input: "Banga" }, function (results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log("google place... success");
} else {
// #TODO: Figure out what to do when the geocoding fails
console.log("error getting google place...");
}
});
Now I see that google is not defined when debugging the Android Phone, where as same when being debugged in ripple, it is working.
is there something on the phone that can prevent the maps from being available to the app?
Regards
Kiran
When my Xamarin app starts, I try to automatically login the user based on some stored credentials.
The login works, but during startup the splash-screen disappears for a second or two showing a black screen.
When I disable the auto-login feature, the splash-screen smoothly transfers to the next view.
Here is the code:
public async void Start(object hint = null)
{
_secureStorageService = Mvx.Resolve<ISecureStorageService>();
ClearParameterCacheUponStart();
SetPushTokenRequirement();
var loginService = Mvx.Resolve<ILoginService>();
var stopwatch = Stopwatch.StartNew();
Debug.WriteLine("Start loginService");
if (HasUsernameAndPassword() && await loginService.TryLoginWithStoredCredentials())
{
ShowViewModel<DashboardViewModel>();
}
else
{
ShowViewModel<LoginViewModel>(true);
}
stopwatch.Stop();
Debug.WriteLine("Finished loginService: {0}ms", stopwatch.ElapsedMilliseconds);
}
Is this the right place to login the user? Or are there any better solutions for this Xamarin-MvvmCross project.
Thanks in advance.
I have the following minimal example of an app using Xamarin.Forms (version 1.2.3) and a MasterDetailPage (similar to: "Show "Back to Menu" Button in iOS NavigationBar with Xamarin.Forms"):
public static class App
{
static MasterDetailPage MDPage;
public static Page GetMainPage()
{
MDPage = new MasterDetailPage {
Master = new ContentPage {
Title = "Master",
Icon = Device.OS == TargetPlatform.iOS ? "menu.png" : null,
Content = new Button {
Text = "Open detail",
Command = new Command(o => {
MDPage.Detail = new NavigationPage(new ContentPage());
MDPage.IsPresented = false;
}),
},
},
Detail = new NavigationPage(new ContentPage()),
};
MDPage.IsPresentedChanged += (sender, e) => Console.WriteLine(DateTime.Now + ": " + MDPage.IsPresented);
return MDPage;
}
}
(hosted on GitHub)
When opening or closing the MasterPage via button click on Android, the IsPresentedChanged event is triggered three times instead of once. According to the command line output the IsPresented property is either toggling as True-False-True or False-True-False, respectively.
Opening or closing using a swipe gesture or tapping on the DetailPage does work well. On iOS there is no problem at all.
Is there something I'm doing wrong? Or is there a simple workaround to get a reliable event?
Ok, with the current version 1.4.0 of Xamarin.Forms the issue seems to be fixed. Opening the slide-out menu yields exactly one "True", closing it yields "False" - just as expected.