0

I was writing an windows phone application using visual phone sdk which give me location of entered address. I was able to do it(Look at below code) but it always redirect to bing maps in next page. But I wanted to add a map and a text field at same page. I will enter the location in text field and maps will show the location (using bing map of visual studio). Is there some good example which I can refer too. It will be a great help.

namespace PhoneApp3
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        BingMapsTask bmt = new BingMapsTask();
        GeoCoordinateWatcher gcw = new GeoCoordinateWatcher();
        public MainPage()
        {
            InitializeComponent();
            map1.CredentialsProvider = new ApplicationIdCredentialsProvider("Your API Key");
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GeoCoordinate gc = new GeoCoordinate(47,-127);
            bmt.Center = gc;

            bmt.ZoomLevel = 9;

            LocationRect.CreateLocationRect(gc);

            bmt.Show();

            //gcw.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(gcw_PositionChanged);
            //gcw.Start();
        }

        void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            textBox1.Text = e.Position.Location.Latitude.ToString();
            textBox2.Text = e.Position.Location.Longitude.ToString();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
            GeoCoordinate gc1 = new GeoCoordinate(47,-126);
            GeoCoordinate gc2 = new GeoCoordinate(47, -127);
            //LabeledMapLocation lml = new LabeledMapLocation("IIT Powai",)
            LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("",gc1);
            LabeledMapLocation spaceNeedleLML2 = new LabeledMapLocation("",gc2);
            bingMapsDirectionsTask.End = spaceNeedleLML;
            bingMapsDirectionsTask.Start = spaceNeedleLML2;
            // If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.

            bingMapsDirectionsTask.Show();
        }

    }
}
Bryant
  • 8,660
  • 1
  • 33
  • 53
Naman
  • 991
  • 2
  • 10
  • 20

1 Answers1

0

The BingMapsTask is designed to launch the Bing Maps app as documented here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.tasks.bingmapstask(v=vs.105).aspx

If I understand your requirements correctly you want to add a map to your application and geocode locations and show them on the map without leaving your app. To do this you will need to add a map to your application as documented here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207045(v=vs.105).aspx

You can then geocode your query using the GeocodeQuery as documented here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj244363(v=vs.105).aspx

rbrundritt
  • 16,570
  • 2
  • 21
  • 46