Exemple #1
0
        public async void storejson()
        {
            string BingMapsKey    = "KKjD0q35Vx6H5bEKB0Fi~zxFLw_EI-jdOpu0Q_NPeKw~AucWpk22LpUKQQtI3AFroBXwMy7c_Ow80Pqm_6m-59x0UDUiPirbvyRRcB8p7wiz";
            string DataSourceID   = "38eef3deca3a48a88d1a88d64a328169";
            string dataSourceName = "stores2";
            string dataEntityName = "RepairShop";
            string accessId       = DataSourceID;
            string bingMapsKey    = BingMapsKey;
            double Radius         = 100; // km

            if (SearchLatitude != 0)
            {
                //testname.Text = SearchLatitude.ToString();
                string shopsurl = string.Format("http://spatial.virtualearth.net/REST/v1/data/{0}/{1}/{2}" +
                                                "?spatialFilter=nearby({3},{4},{5})&$format=json&$select=*,__Distance&key={6}", accessId, dataSourceName,
                                                dataEntityName, SearchLatitude, SearchLongitude, Radius, bingMapsKey);

                try
                {
                    HttpClient          client   = new HttpClient();
                    HttpResponseMessage response = await client.GetAsync(shopsurl);

                    response.EnsureSuccessStatusCode();
                    string responsetext = await response.Content.ReadAsStringAsync();

                    obj = JsonConvert.DeserializeObject <shopsdata.restObj>(responsetext);
                }
                catch (Exception)
                {
                    ShowMessage("connect to internet and try again");
                }

                // Serialize our Product class into a string
                // Changed to serialze the List
                string jsonContents = JsonConvert.SerializeObject(obj);

                // Get the app data folder and create or replace the file we are storing the JSON in.
                StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                StorageFile   textFile    = await localFolder.CreateFileAsync("a.txt", CreationCollisionOption.ReplaceExisting);

                // Open the file...
                using (IRandomAccessStream textStream = await textFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    // write the JSON string!
                    using (DataWriter textWriter = new DataWriter(textStream))
                    {
                        textWriter.WriteString(jsonContents);
                        await textWriter.StoreAsync();
                    }
                }
            }
            else
            {
                ShowMessage("Try After Sometime, Getting Your present Location");
            }
        }
Exemple #2
0
        public async void Job()
        {
            Debug.WriteLine("job Start");
            //Deserialize json from file "a.txt"
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            try
            {
                // Getting JSON from file if it exists, or file not found exception if it does not
                StorageFile textFile = await localFolder.GetFileAsync("a.txt");

                using (IRandomAccessStream textStream = await textFile.OpenReadAsync())
                {
                    // Read text stream
                    using (DataReader textReader = new DataReader(textStream))
                    {
                        //get size
                        uint textLength = (uint)textStream.Size;
                        await textReader.LoadAsync(textLength);

                        // read it
                        string jsonContents = textReader.ReadString(textLength);
                        // deserialize back to our products!
                        //I only had to change this following line in this function
                        obj = JsonConvert.DeserializeObject <shopsdata.restObj>(jsonContents);
                    }
                }
            }
            catch (Exception ex)
            {
                string mes = "Exception: " + ex.Message;
                ShowMessage(mes);
            }

            //DeSerialization Complete
            //Sending data to List Box
            try
            {
                GeocodeResults.ItemsSource = obj.d.results;
                Debug.WriteLine("job done");
            }
            catch (Exception)
            {
                ShowMessage("No Stored Data Available Plz start internet");
            }
        }
Exemple #3
0
        public async void Job()
        {
            //storejson();

            //Deserialize json from file "a.txt"
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            try
            {
                // Getting JSON from file if it exists, or file not found exception if it does not
                StorageFile textFile = await localFolder.GetFileAsync("a.txt");

                using (IRandomAccessStream textStream = await textFile.OpenReadAsync())
                {
                    // Read text stream
                    using (DataReader textReader = new DataReader(textStream))
                    {
                        //get size
                        uint textLength = (uint)textStream.Size;
                        await textReader.LoadAsync(textLength);

                        // read it
                        string jsonContents = textReader.ReadString(textLength);
                        // deserialize back to our products!
                        //I only had to change this following line in this function
                        obj = JsonConvert.DeserializeObject <shopsdata.restObj>(jsonContents);
                    }
                }
            }
            catch (Exception ex)
            {
                string mes = "Exception: " + ex.Message;
                ShowMessage(mes);
            }

            //DeSerialization Complete
            //Sending data to List Box
            try
            {
                Debug.WriteLine("job done");


                foreach (AutoRepairPhone.shopsdata.Result l in obj.d.results)
                {
                    //Get the location of each result
                    Geopoint location = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = l.Latitude, Longitude = l.Longitude
                    });

                    //Create a pushpin each location

                    var jayway = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = l.Latitude, Longitude = l.Longitude
                    });
                    var youPin = CreatePin();
                    MyMap.Children.Add(youPin);
                    MapControl.SetLocation(youPin, jayway);
                    MapControl.SetNormalizedAnchorPoint(youPin, new Point(0.0, 1.0));
                    //string title = this.resourceLoader.GetString("Voisietequi");
                    MyMap.TrySetViewAsync(jayway, 15, 0, 0, MapAnimationKind.Bow);
                }
                //Pass the results to the item source of the GeocodeResult ListBox
                MyMap.ZoomLevel            = 14;
                GeocodeResults.ItemsSource = obj.d.results;
            }
            catch (Exception)
            {
                ShowMessage("No Stored Data Available Plz start internet");
            }


            i = 1;
        }
Exemple #4
0
        public async void routemap()
        {
            string BingMapsKey  = "KKjD0q35Vx6H5bEKB0Fi~zxFLw_EI-jdOpu0Q_NPeKw~AucWpk22LpUKQQtI3AFroBXwMy7c_Ow80Pqm_6m-59x0UDUiPirbvyRRcB8p7wiz";
            string DataSourceID = "38eef3deca3a48a88d1a88d64a328169";
            string bingMapsKey  = BingMapsKey;

            if (SearchLatitude != 0)
            {
                string routeurl = string.Format("https://spatial.virtualearth.net/REST/v1/data/38eef3deca3a48a88d1a88d64a328169/stores2/RepairShop" +
                                                "?spatialFilter=nearRoute('{0}','{1}')&$format=json&$select=*,__Distance&key={2}", fromlocation, tolocation, bingMapsKey);

                try
                {
                    HttpClient          client   = new HttpClient();
                    HttpResponseMessage response = await client.GetAsync(routeurl);

                    string responsetext = await response.Content.ReadAsStringAsync();

                    obj = JsonConvert.DeserializeObject <shopsdata.restObj>(responsetext);


                    // Serialize our Product class into a string
                    // Changed to serialze the List
                    string jsonContents = JsonConvert.SerializeObject(obj);

                    // Get the app data folder and create or replace the file we are storing the JSON in.
                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile   textFile    = await localFolder.CreateFileAsync("a.txt", CreationCollisionOption.ReplaceExisting);

                    // Open the file...
                    using (IRandomAccessStream textStream = await textFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        // write the JSON string!
                        using (DataWriter textWriter = new DataWriter(textStream))
                        {
                            textWriter.WriteString(jsonContents);
                            await textWriter.StoreAsync();
                        }
                    }

                    {
                        //LocationCollection locations = new LocationCollection();
                        try
                        {
                            foreach (AutoRepairPhone.shopsdata.Result l in obj.d.results)
                            {
                                //Get the location of each result
                                Geopoint location = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = l.Latitude, Longitude = l.Longitude
                                });

                                //Create a pushpin each location

                                var jayway = new Geopoint(new BasicGeoposition()
                                {
                                    Latitude = l.Latitude, Longitude = l.Longitude
                                });
                                var youPin = CreatePin();
                                MyMap.Children.Add(youPin);
                                MapControl.SetLocation(youPin, jayway);
                                MapControl.SetNormalizedAnchorPoint(youPin, new Point(0.0, 1.0));
                                //string title = this.resourceLoader.GetString("Voisietequi");
                                MyMap.TrySetViewAsync(jayway, 15, 0, 0, MapAnimationKind.Bow);
                            }
                            //Pass the results to the item source of the GeocodeResult ListBox
                            MyMap.ZoomLevel            = 14;
                            GeocodeResults.ItemsSource = obj.d.results;
                        }
                        catch
                        {
                            ShowMessage("no data available");
                        }
                    }

                    i = 1;
                }
                catch (Exception)
                {
                    ShowMessage("connect to internet and try again");
                }
            }

            else
            {
                ShowMessage("Getting Gps");
            }
        }