Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual Studio 2010中用于Windows Phone Notefunction的C#项目_C#_Windows_Visual Studio 2010_Web Services_Windows Phone 7 - Fatal编程技术网

Visual Studio 2010中用于Windows Phone Notefunction的C#项目

Visual Studio 2010中用于Windows Phone Notefunction的C#项目,c#,windows,visual-studio-2010,web-services,windows-phone-7,C#,Windows,Visual Studio 2010,Web Services,Windows Phone 7,我试图让我的记事本功能,以张贴您当前所在的城市使用您的gps坐标时,保存一个便笺。现在它只显示“未知位置”。我现在有点迷路了,我用这个代码工作了这么长时间,试图让它工作,所以请任何人告诉我我做错了什么 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using Syste

我试图让我的记事本功能,以张贴您当前所在的城市使用您的gps坐标时,保存一个便笺。现在它只显示“未知位置”。我现在有点迷路了,我用这个代码工作了这么长时间,试图让它工作,所以请任何人告诉我我做错了什么

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;
using System.Text;
using System.IO.IsolatedStorage;
using System.IO;
using Secret.myTerraService;

namespace Secret
{
public partial class AddNotePage : PhoneApplicationPage
{
    private IsolatedStorageSettings settings =     IsolatedStorageSettings.ApplicationSettings;
    private string location = "";

    #region Hämtar din geografiska position

    public AddNotePage()
    {
        InitializeComponent();
        GeoCoordinateWatcher watcher;

        watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default)
                           {
                               MovementThreshold = 20
                           };

        watcher.PositionChanged += this.watcher_PositionChanged;
        watcher.StatusChanged += this.watcher_StatusChanged;
        watcher.Start();

    }
private void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
    case GeoPositionStatus.Disabled:
        // location is unsupported on this device
        break;
    case GeoPositionStatus.NoData:
        // data unavailable
        break;
}
}

private void watcher_PositionChanged(object sender,   GeoPositionChangedEventArgs<GeoCoordinate> e)
{
var epl = e.Position.Location;

// Access the position information thusly:
epl.Latitude.ToString("0.000");
epl.Longitude.ToString("0.000");
epl.Altitude.ToString();
epl.HorizontalAccuracy.ToString();
epl.VerticalAccuracy.ToString();
epl.Course.ToString();
epl.Speed.ToString();
e.Position.Timestamp.LocalDateTime.ToString();




}

void client_ConvertLonLatPtToNearestPlaceCompleted(object sender,   myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs e)
{
location = e.Result;

//throw new NotImplementedException();
}


    #endregion

    #region Knappfunktioner

    private void AppBar_Cancel_Click(object sender, EventArgs e)
    {
        navigateBack();
    }

    private void AppBar_Save_Click(object sender, EventArgs e)
    { // spara en ny anteckning
        if (location.Trim().Length == 0)
        {
            location = "Okänd Plats";
        }

        // skapa namnet på filen
        StringBuilder sb = new StringBuilder();
        sb.Append(DateTime.Now.Year);
        sb.Append("_");
        sb.Append(String.Format("{0:00}", DateTime.Now.Month));
        sb.Append("_");
        sb.Append(String.Format("{0:00}", DateTime.Now.Day));
        sb.Append("_");
        sb.Append(String.Format("{0:00}", DateTime.Now.Hour));
        sb.Append("_");
        sb.Append(String.Format("{0:00}", DateTime.Now.Minute));
        sb.Append("_");
        sb.Append(String.Format("{0:00}", DateTime.Now.Second));
        sb.Append("_");

        location = location.Replace(" ", "-");
        location = location.Replace(", ", "_");
        sb.Append(location);
        sb.Append(".txt");

        //spara filen i Isolated Storage
        var appStorage = IsolatedStorageFile.GetUserStoreForApplication();

        try
        {
            using (var fileStream = appStorage.OpenFile(sb.ToString(),  System.IO.FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fileStream))
                {
                    sw.WriteLine(editTextBox.Text);
                }
            }

        }
        catch
        {
            // åtgärda vid senare tillfälle..
        }



        //Klart Navigera tillbaka till NoteMainPage
        navigateBack();

    }
使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用Microsoft.Phone.Controls;
使用系统、设备、位置;
使用系统文本;
使用System.IO.IsolatedStorage;
使用System.IO;
使用Secret.myTerraService;
名称空间秘密
{
公共部分类AddNotePage:PhoneApplicationPage
{
私有隔离存储设置=隔离存储设置。应用程序设置;
私有字符串位置=”;
#赫马尔丁地区地理位置
公共AddNotePage()
{
初始化组件();
地球坐标观测员;
watcher=新的地理坐标记录器(GeoPositionAccuracy.Default)
{
MovementThreshold=20
};
watcher.PositionChanged+=此.watcher\u PositionChanged;
watcher.StatusChanged+=this.watcher\u StatusChanged;
watcher.Start();
}
私有无效观察者\u状态已更改(对象发送者,地理位置状态更改Deventargs e)
{
开关(如状态)
{
案例地理位置状态。已禁用:
//此设备上不支持此位置
打破
案例地理位置status.NoData:
//数据不可用
打破
}
}
私有无效观察者位置已更改(对象发送者,地理位置更改Deventargs e)
{
var epl=e.Position.Location;
//通过以下方式访问位置信息:
epl纬度ToString(“0.000”);
epl.经度ToString(“0.000”);
epl.海拔高度ToString();
epl.HorizontalAccurance.ToString();
epl.VerticalAccuracy.ToString();
epl.Course.ToString();
epl.Speed.ToString();
e、 Position.Timestamp.LocalDateTime.ToString();
}
无效客户端\u ConvertLonLatPtToNearestPlaceCompleted(对象发送方,myTerraService.ConvertLonLatPtToNearestPlaceCompleted事件参数e)
{
位置=e.结果;
//抛出新的NotImplementedException();
}
#端区
#区域Knappfunktioner
私有无效AppBar\u取消\u单击(对象发送者,事件参数e)
{
导航返回();
}
私有void AppBar_保存_单击(对象发送方,事件参数e)
{//spara en ny anteckning
if(location.Trim().Length==0)
{
location=“Okänd Plats”;
}
//斯卡帕·纳姆内特·帕菲伦
StringBuilder sb=新的StringBuilder();
sb.Append(DateTime.Now.Year);
某人附加(“”);
sb.Append(String.Format(“{0:00}”,DateTime.Now.Month));
某人附加(“”);
sb.Append(String.Format(“{0:00}”,DateTime.Now.Day));
某人附加(“”);
追加(String.Format(“{0:00}”,DateTime.Now.Hour));
某人附加(“”);
sb.Append(String.Format(“{0:00}”,DateTime.Now.Minute));
某人附加(“”);
追加(String.Format(“{0:00}”,DateTime.Now.Second));
某人附加(“”);
位置=位置。替换(“,“-”);
位置=位置。替换(“,”,“”);
某人(地点);
sb.追加(“.txt”);
//spara文件i独立存储
var appStorage=IsolatedStorageFile.GetUserStoreForApplication();
尝试
{
使用(var fileStream=appStorage.OpenFile(sb.ToString(),System.IO.FileMode.Create))
{
使用(StreamWriter sw=新StreamWriter(fileStream))
{
sw.WriteLine(editTextBox.Text);
}
}
}
抓住
{
//åtgärda vid senare tilfälle。。
}
//克拉特·纳维格拉·蒂尔巴卡直到记事本主页
导航返回();
}

在测试此功能时,我可以看到您的代码可能会中断的几个点。您应该使用断点进行调试,以实际确认您的应用程序正在获取GPS位置数据。如果没有,请使用Windows Phone emulator并运行GPS模拟(然后再次确认)

下一步,一旦您知道您的GPS数据正在进入Terra Web服务并正确格式化,请确认数据实际上正在发送到Terra Web服务,并且数据正在从Web服务调用返回。如果您的Terra Web服务返回“未知位置”尽管如此,请再试一次,但这一次绘制主要城市附近的GPS位置,以增加web服务知道您靠近哪个城市的几率。如果您仍然返回“未知位置”,则您可以相当肯定问题在于web服务提供商

根据我使用Windows Phone定位服务的经验(我只使用过具有WiFi接入的dev手机(即没有sim卡)),位置数据有时需要几秒钟或几分钟才能获取。如果您在地下室或GPS无法找到您的区域的物理开发手机上进行测试,则很可能无法生成数据。此外,由于Windows phone位置数据不一定是即时的,因此您不能随时调用它并期待它准备好位置数据。根据我的经验,我让用户选择使用位置服务(根据Windows Phone Marketplace提交要求),然后让后台代理在用户使用应用程序时提取位置数据。这样,位置数据可能在用户需要时准备好(如用户保存注释时的示例)

下面是我在C#中为您制作的一个工作示例,它将适用于您的Windows Phone应用程序。出于简单性和时间的考虑,该示例是一个控制台应用程序。如果您仍然无法理解它,我将
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TerraServiceExample.com.msrmaps; // add the service using statement
// http://msrmaps.com/terraservice2.asmx
namespace TerraServiceExample
{
    class Program
    {
        /// <summary> The main entry point for the application. </summary>
        static void Main(string[] args)
        {

            // Create the GPS point from your location services data
            LonLatPt location = new LonLatPt();

            // Modify Lat and Lon based on your needs
            // This example uses the GPS Coordinates for "Eau Claire, Wisconsin, United States"
            location.Lat = 44.811349;
            location.Lon = -91.498494;

            // Create a new TerraService object
            TerraService ts = new TerraService();

            // Output the nearest location from the TerraService
            Console.WriteLine(ts.ConvertLonLatPtToNearestPlace(location));

            // For console app to stay open/close easily
            Console.WriteLine("Press any key to close window...");
            Console.ReadKey();

            // Lastly, appreciate the Microsoft folks that made this available for free
            // They are all interesting individuals but you should read about Jim Gray via Wikipedia to
            // understand some history behind this cool web service.
        }
    }
}