我正在开发一个项目,其中包括一个用于控制/转向的Android应用程序.
我已经写了一些似乎工作正常的代码.但是当我仔细观察时,我发现有些价值观很奇怪.
当我向前/向后倾斜手机以处理速度时,它可以完美地运行,我得到了预期的速度和方向值.但是,当我向左/右倾斜手机以处理方向时,它似乎会破坏某些值.当它向左/向右倾斜时,不仅改变方向值(滚动),而且还影响速度值(俯仰).
有关其他信息:
我用来读取传感器值的最相关代码如下:
public void onSensorChanged(SensorEvent sensorEvent)
{
synchronized (this)
{
if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
float azimuth = sensorEvent.values[0]; // azimuth rotation around the z-axis
float pitch = sensorEvent.values[1]; // pitch rotation around the x-axis
float roll = sensorEvent.values[2]; // roll rotation around the y-axis
System.out.println("pitch: " + pitch);
System.out.println("roll: " + roll);
System.out.println("--------------------");
// Convert the sensor values to the actual speed and direction values …Run Code Online (Sandbox Code Playgroud) 当我在View Alternate中时,我知道我可以通过以下方式获取ContentItem的显示URL:
@Url.ItemDisplayUrl(contentItem)
但是当我在控制器上下文(ActionResult)时,我不知道如何获取显示URL.出于站点地图的目的,我需要列出的ContentItems的URL.
我正在使用下面的代码.
public class SiteMapResult : ActionResult
{
readonly IContentManager _contentManager;
readonly ITagService _tagService;
public SiteMapXmlResult(IContentManager contentManager, ITagService tagService)
{
_contentManager = contentManager;
_tagService = tagService;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml";
string host = context.HttpContext.Request.Url.Host;
StringBuilder xml = new StringBuilder();
xml.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
xml.Append(@"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">");
var contentItems = _contentManager.Query(VersionOptions.Latest, GetContentTypeNames().ToArray()).List();
foreach (var contentItem in contentItems)
{
// The display url of contentItem
}
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何获取ContentItem显示URL?