Amanda_Panda
Amanda_Panda

Reputation: 1186

Plotting geocoordinates in a Windows 8/Bing maps app

I'm making a C#/XAML Windows 8 app using Bing Maps. I'm copying a bunch of Windows Phone 7 code over, and I'm having a problem simply plotting geocoords. Here's the WP7 code:

GeoCoordinate mapCenter = new GeoCoordinate(37.784, -122.408);
map1.Center = mapCenter;

However, when I try to instantiate mapCenter in Win 8, (and I do use lowercase Geocoordinate instead of GeoCoordinate) I get an error saying that "Windows.Devices.Geolocation.Geocoordinate does not contain a constructor that takes 2 arguments".

I'm sorta stumped, as I planned on using Geocoordinates quite a bit, and I'm not really sure how to figure out what exactly the Geocoordinate constructor takes.

thanks,

Amanda

Edited to fix code indentation

Upvotes: 2

Views: 1961

Answers (2)

Jonathan pace
Jonathan pace

Reputation: 1

Your code and you error output are saying two different things. I had the same problem make sure you are using the capital C in GeoCoordianate in you code. teh lower case C in geocoordinate is for getting the phones location.

The Center property of the Map control requires a value of type GeoCoordinate from the System.Device.Location namespace. If you are using location services from the Windows.Devices.Geolocation namespace, you have to convert a Windows.Devices.Geolocation.Geocoordinate value to a System.Device.Location.GeoCoordinate value for use with the Map control.

You can get an extension method to do this conversion, along with other useful extensions to the Maps API, by downloading the Windows Phone Toolkit. If you want to write your own code, here is an example of a method that you can use to convert a Geocoordinate to a >GeoCoordinate:

from http://msdn.microsoft.com/en-US/library/windowsphone/develop/jj207045(v=vs.105).aspx#BKMK_converting

Upvotes: 0

Justin Niessner
Justin Niessner

Reputation: 245479

The Windows.Devices.Geolocation.Geocoordinate class cannot be directly instantiated. Also, keep in mind, that the namespace you are using is used specifically for retrieving location data from the device.

First, you'll need to get an instance of Geoposition via Geolocator.GetGeopositionAsync.

You can then get the Geocoordinate instance from Geoposition.Coordinate.

If you're looking to simply center the map on a given latitude and longitude (and you're using the Bing Maps for Windows Store Apps SDK), it looks like you should be using the Location class instead (as Map.Center is of type Location).

Upvotes: 2

Related Questions