Jan 21, 2011 at 12:10 AM, Mintydog wrote

I got mine working after closing VS and instead of using the .asmx address I ued the

http://msrmaps.com/TerraService2.asmx?WSDL

And it worked fine. Pretty cool feature, although just looking at the code is a bit confusing. Anyway, I had the problem that no coordinates were retrieved. But...

I've to say that this comment helped me a lot for adding the Service Reference.

Dec 28, 2010 at 11:18 AM, Saji Abraham wrote

On the phone device, I was unable to get the GeoCoordinateWatcher class to work as shown in the video. Rather, I had to use:
watcher =new GeoCoordinateWatcher();
watcher.PositionChanged +=new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.Start(); // TryStart works too.
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
var myPosition = watcher.Position;
watcher.Stop(); 
... 
}

This second post solve the other problem. Hence, for sake of clarity, I am posting here my full code in order to give to everybody the possibility of having a working program.

 

<Button Content="Find Me" Height="72" HorizontalAlignment="Left" Margin="290,135,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="6,6,0,0" Name="myPositionTextBlock" Text="" VerticalAlignment="Top" Width="444" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="6,42,0,0" Name="myLatitudeTextBlock" Text="" VerticalAlignment="Top" Width="444" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="6,78,0,0" Name="myLongitudeTextBlock" Text="" VerticalAlignment="Top" Width="444" />

 

GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher();private void button1_Click(object sender, RoutedEventArgs e)        {                        // Added lines of code            myWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(myWatcher_PositionChanged);            myWatcher.Start();            myLongitudeTextBlock.Text = myLatitudeTextBlock.Text = myPositionTextBlock.Text = "";        }        void myWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)        {            var myPosition = myWatcher.Position;            myWatcher.Stop();            double latitude = 0;            double longitude = 0;            if (!myPosition.Location.IsUnknown)            {                latitude = myPosition.Location.Latitude;                longitude = myPosition.Location.Longitude;            }            myLatitudeTextBlock.Text = string.Format("Latitude: {0}", latitude);            myLongitudeTextBlock.Text = string.Format("Longitude: {0}", longitude);            myTerraService.TerraServiceSoapClient client = new myTerraService.TerraServiceSoapClient();            client.ConvertLonLatPtToNearestPlaceCompleted += new EventHandler<myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs>(client_ConvertLonLatPtToNearestPlaceCompleted);            client.ConvertLonLatPtToNearestPlaceAsync(new myTerraService.LonLatPt { Lat = latitude, Lon = longitude });            //throw new NotImplementedException();        }        void client_ConvertLonLatPtToNearestPlaceCompleted(object sender, myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs e)        {            myPositionTextBlock.Text = e.Result;            //throw new NotImplementedException();        }