magnetometer Overview
Devices with magnetometer hardware support can determine the angle relative to the Arctic according to the magnetometer
The magnetometer access API is defined in the Compass class
Call mode is similar to the accelerometer
1 <GridBackground= "White">2 <ImageSource= "Compass.png"Rendertransformorigin= "0.5,0.5">3 <Image.rendertransform>4 <Compositetransformx:name= "Rotate"Rotation= "1"/>5 </Image.rendertransform>6 </Image>7 </Grid>
1 protected Override voidonnavigatedto (NavigationEventArgs e)2 {3Compass C =Compass.getdefault ();4 if(c = =NULL)5 {6 //Compass not supported7 return;8 }9C.readingchanged + =Async(P1, p2) =Ten { One //Modify the rotation angle of the picture; A System.Diagnostics.Debug.WriteLine (p2. Reading.HeadingTrueNorth.Value); - await This. Dispatcher.runasync (Windows.UI.Core.CoreDispatcherPriority.Normal, () = - { theRotate. Rotation =-P2. Reading.HeadingTrueNorth.Value; - }); - }; -C.reportinterval = C.minimumreportinterval *Ten; +}
Windows Phone 18, Compass