Beispiel #1
0
        public Address GetAddress(string name)
        {
            Geocoder        geocoder = new Geocoder(Instance, Locale.Default);
            IList <Address> address  = geocoder.GetFromLocationName(name, 1);

            return(address[0]);
        }
Beispiel #2
0
        private double[] getLocation()
        {
            var location = new double[2];

            Geocoder geo = new Geocoder(this);

            try
            {
                List <Address> addressList = geo.GetFromLocationName(addressToGeoLocator, 5).ToList();
                Address        address     = addressList[0];
                if (address == null)
                {
                    return(null);
                }

                location[0] = address.Latitude;
                location[1] = address.Longitude;

                return(location);
            }
            catch (Exception e)
            {
            }

            return(null);
        }
Beispiel #3
0
        public void OnLocationChanged(Location location)
        {
            try {
                _currentLocation = location;

                if (_currentLocation == null)
                {
                    _location = "Unable to determine your location.";
                }
                else
                {
                    _location = String.Format("{0},{1}", _currentLocation.Latitude, _currentLocation.Longitude);

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                    Address addressCurrent = addressList.FirstOrDefault();

                    if (addressCurrent != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < addressCurrent.MaxAddressLineIndex; i++)
                        {
                            deviceAddress.Append(addressCurrent.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        _address = deviceAddress.ToString();
                    }
                    else
                    {
                        _address = "Unable to determine the address.";
                    }

                    IList <Address> source        = geocoder.GetFromLocationName(_sourceAddress, 1);
                    Address         addressOrigin = source.FirstOrDefault();

                    var coord1 = new LatLng(addressOrigin.Latitude, addressOrigin.Longitude);
                    var coord2 = new LatLng(addressCurrent.Latitude, addressCurrent.Longitude);

                    var distanceInRadius = Utils.HaversineDistance(coord1, coord2, Utils.DistanceUnit.Miles);

                    _remarks = string.Format("Your are {0} miles away from your original location.", distanceInRadius);

                    Intent intent = new Intent(this, typeof(GPSServiceReciever));
                    intent.SetAction(GPSServiceReciever.LOCATION_UPDATED);
                    intent.AddCategory(Intent.CategoryDefault);
                    intent.PutExtra("Location", _location);
                    intent.PutExtra("Address", _address);
                    intent.PutExtra("Remarks", _remarks);
                    SendBroadcast(intent);
                }
            }
            catch (Exception ex) {
                _address = "Unable to determine the address.";
            }
        }
Beispiel #4
0
 //Tom: 以地址擷取經緯度資料
 protected void GetLocationFromAddress(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(_addrEditText.Text))
     {
         Geocoder        geo  = new Geocoder(this);
         IList <Address> addr = geo.GetFromLocationName(_addrEditText.Text, 1);
         try{
             //Tom: 如果定位系統有傳回資料,則判斷是否有經緯度資訊
             if (addr.First().HasLatitude&& addr.First().HasLongitude)
             {
                 _latEditText.Text  = addr.First().Latitude.ToString();
                 _longEditText.Text = addr.First().Longitude.ToString();
             }
         }catch {
             //Tom: 定位系統未傳回資料,addr 是 null or empty
             AlertDialog.Builder alertConfirm = new AlertDialog.Builder(this);
             alertConfirm.SetCancelable(false);
             alertConfirm.SetPositiveButton("定位", GetLocationClicked);
             alertConfirm.SetNegativeButton("取消", delegate {});
             alertConfirm.SetTitle("無經緯度資訊!");
             alertConfirm.SetMessage(String.Format("此地址查無經緯度資訊,請按[定位]以取得目前所在位置經緯度\n" +
                                                   ",或按[取消]暫時忽略經緯度。"));
             alertConfirm.Show();
         }
     }
 }
Beispiel #5
0
        /* public  async void GetPosition(GoogleMap googleMap)
         * {
         *   try
         *   {
         *       var locator = CrossGeolocator.Current;
         *           locator.DesiredAccuracy = 50;
         *       if (locator.IsGeolocationEnabled)
         *       {
         *           var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(1000));
         *           LatLng coordonne = new LatLng(position.Latitude, position.Longitude);
         *           MarkerOptions markerOptions = new MarkerOptions();
         *           markerOptions.SetPosition(new LatLng(position.Latitude, position.Longitude));
         *           markerOptions.SetTitle("Ma Position");
         *           googleMap.AddMarker(markerOptions);
         *           googleMap.MoveCamera(CameraUpdateFactory.NewLatLng(coordonne));
         *       }
         *       else
         *       {
         *           Console.WriteLine("La location ne trouve pas, geolocator est éteint.");
         *       }
         *
         *
         *   }
         *   catch (Exception le)
         *   {
         *
         *       Console.WriteLine(le+"La location ne trouve pas.");
         *   }
         * }*/

        public void GetLocationFromAddress(string strAddress, int id, GoogleMap googleMap)
        {
            Geocoder coder = new Geocoder(this);

            IList <Address> address       = null;
            MarkerOptions   markerOptions = new MarkerOptions();

            markerOptions.SetSnippet(strAddress);
            address = coder.GetFromLocationName(strAddress, 5);
            if (address == null)
            {
                return;
            }
            else
            {
                for (int i = 0; i < address.Count; i++)
                {
                    Address ad = address[i];

                    markerOptions.SetPosition(new LatLng(ad.Latitude, ad.Longitude));
                    markerOptions.SetTitle(listArtisan[id]);

                    googleMap.AddMarker(markerOptions);
                }
                googleMap.SetInfoWindowAdapter(this);
            }
        }
Beispiel #6
0
        /// <summary>
        /// creates marker from the provided list
        /// </summary>
        /// <param name="googleMap"></param>
        public void OnMapReady(GoogleMap googleMap)
        {
            this.GMap = googleMap;

            //get list of locations and add it to a list of Strings(listOfLocations)
            List <string> listOfLocations = new List <string>()
            {
                "Conestoga College Doon Campus, Kitchener, ON",
                "100 Old Carriage Drive, Kitchener, ON"
            };

            foreach (String location in listOfLocations)
            {
                var    geo = new Geocoder(this);
                var    addresses = geo.GetFromLocationName(location, 1);
                double lat = 0, lon = 0;
                foreach (Address address in addresses)
                {
                    lat = address.Latitude;
                    lon = address.Longitude;
                }
                LatLng       latlng = new LatLng(lat, lon);
                CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 15);
                GMap.MoveCamera(camera);
                MarkerOptions options = new MarkerOptions();
                options.SetPosition(latlng);
                options.SetSnippet(location);
                GMap.AddMarker(options);
                GMap.MarkerClick += GMap_MarkerClick;
            }
        }
Beispiel #7
0
 static Address GetLocationFromAddress(string strAddress)
 {
     using (var coder = new Geocoder(UIRuntime.CurrentActivity))
     {
         var address = coder.GetFromLocationName(strAddress, 5).ToList();
         return(address?[0]);
     }
 }
        public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder)
        {
            var query = uri.LastPathSegment.ToLowerInvariant();

            IList <Address> addresses = null;

            try {
                addresses = geocoder.GetFromLocationName(query,
                                                         SuggestionCount,
                                                         LowerLeftLat,
                                                         LowerLeftLon,
                                                         UpperRightLat,
                                                         UpperRightLon);
            } catch (Exception e) {
                Xamarin.Insights.Report(e);
                Android.Util.Log.Warn("SuggestionsFetcher", e.ToString());
                addresses = new Address[0];
            }

            var cursor = new MatrixCursor(new string[] {
                BaseColumns.Id,
                SearchManager.SuggestColumnText1,
                SearchManager.SuggestColumnText2,
                SearchManager.SuggestColumnIntentExtraData
            }, addresses.Count);

            long id = 0;

            foreach (var address in addresses)
            {
                int dummy;
                if (int.TryParse(address.Thoroughfare, out dummy))
                {
                    continue;
                }

                var options1 = new string[] { address.FeatureName, address.Thoroughfare };
                var options2 = new string[] { address.Locality, address.AdminArea };

                var line1 = string.Join(", ", options1.Where(s => !string.IsNullOrEmpty(s)).Distinct());
                var line2 = string.Join(", ", options2.Where(s => !string.IsNullOrEmpty(s)));

                if (string.IsNullOrEmpty(line1) || string.IsNullOrEmpty(line2))
                {
                    continue;
                }

                cursor.AddRow(new Java.Lang.Object[] {
                    id++,
                    line1,
                    line2,
                    address.Latitude + "|" + address.Longitude
                });
            }

            return(cursor);
        }
Beispiel #9
0
        private void locate()
        {
            string   searchString = searchText.Text;
            Geocoder geocoder     = new Geocoder(this);
            var      list         = geocoder.GetFromLocationName(searchString, 1);

            if (list.Count > 0)
            {
                Address address = list[0];
                moveCamera(new LatLng(address.Latitude, address.Longitude), 15f, address.GetAddressLine(0));
            }
        }
Beispiel #10
0
        //ILocationListener methods
        public void OnLocationChanged(Location location)
        {
            try {
                _currentLocation = location;

                if (_currentLocation == null)
                {
                    _locationText.Text = "Unable to determine your location.";
                }
                else
                {
                    _locationText.Text = String.Format("{0},{1}", _currentLocation.Latitude, _currentLocation.Longitude);

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                    Address addressCurrent = addressList.FirstOrDefault();

                    if (addressCurrent != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < addressCurrent.MaxAddressLineIndex; i++)
                        {
                            deviceAddress.Append(addressCurrent.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        _addressText.Text = deviceAddress.ToString();
                    }
                    else
                    {
                        _addressText.Text = "Unable to determine the address.";
                    }

                    IList <Address> source        = geocoder.GetFromLocationName(_sourceAddress, 1);
                    Address         addressOrigin = source.FirstOrDefault();

                    var coord1 = new LatLng(addressOrigin.Latitude, addressOrigin.Longitude);
                    var coord2 = new LatLng(addressCurrent.Latitude, addressCurrent.Longitude);

                    var distance = Utils.HaversineDistance(coord1, coord2, Utils.DistanceUnit.Miles);

                    _remarksText.Text = string.Format("Your are {0} miles away from your original location.", distance);
                }
            }
            catch {
                _addressText.Text = "Unable to determine the address.";
            }
        }
Beispiel #11
0
        public LatLng getLatLngFromName(string name)
        {
            //This Method takes a Location name as an argument and returns the LatLng Object of the Location
            LatLng geoPoint;

            Geocoder geocoder = new Geocoder(this);

            IList <Android.Locations.Address> list = geocoder.GetFromLocationName(name, 5);

            Android.Locations.Address address = list[0];

            geoPoint = new LatLng(address.Latitude, address.Longitude);

            return(geoPoint);
        }
        async Task <string> GeocodeToConsoleAsync(string address)
        {
            var geo = new Geocoder(this);

            var addresses = geo.GetFromLocationName(address, 1);

            RunOnUiThread(() =>
            {
                addresses.ToList().ForEach((addr) =>
                {
                    SetWorkMarker(addr);
                });
            });
            return("");
        }
Beispiel #13
0
 public void OnMapReady(GoogleMap googleMap)
 {
     this.GMap = googleMap;
     //var location = GetLocation(address);
     try{
         var geo       = new Geocoder(this);
         var addresses = geo.GetFromLocationName(address, 1);
         GMap.UiSettings.ZoomControlsEnabled = true;
         LatLng       latlng = new LatLng(Convert.ToDouble(addresses[0].Latitude), Convert.ToDouble(addresses[0].Longitude));
         CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 5);
         GMap.MoveCamera(camera);
         MarkerOptions options = new MarkerOptions().SetPosition(latlng).SetTitle(address);
         GMap.AddMarker(options);
     }catch (Exception e) {
         Console.WriteLine("Map:OnMapReadyExecption" + e.Message);
     }
 }
        private Location GetLocationFromAddress(string strAddress)
        {
            Location        rLocation = null;
            Geocoder        coder     = new Geocoder(mContext);
            IList <Address> address;

            try
            {
                address = coder.GetFromLocationName(strAddress, 5);
                Address location = address[0];
                rLocation           = new Location("Store");
                rLocation.Latitude  = location.Latitude;
                rLocation.Longitude = location.Longitude;
                return(rLocation);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
            protected override FilterResults PerformFiltering(Java.Lang.ICharSequence constraint)
            {
                if (constraint == null)
                {
                    return new FilterResults()
                           {
                               Count = 0, Values = null
                           }
                }
                ;
                var search    = constraint.ToString();
                var addresses = geocoder.GetFromLocationName(search, 7,
                                                             LowerLeftLat,
                                                             LowerLeftLon,
                                                             UpperRightLat,
                                                             UpperRightLon);

                return(new FilterResults()
                {
                    Count = addresses.Count,
                    Values = (Java.Lang.Object)addresses
                });
            }
Beispiel #16
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var button = FindViewById <Button> (Resource.Id.geocodeButton);

            button.Click += (sender, e) => {
                new Thread(new ThreadStart(() => {
                    var geo = new Geocoder(this);

                    var addresses = geo.GetFromLocationName("50 Church St, Cambridge, MA", 1);

                    RunOnUiThread(() => {
                        var addressText = FindViewById <TextView> (Resource.Id.addressText);

                        addresses.ToList().ForEach((addr) => {
                            addressText.Append(addr.ToString() + "\r\n\r\n");
                        });
                    });
                })).Start();
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            try
            {
                SetContentView(Resource.Layout.NewProfileCoordsMap);
                user_descriptor    = BitmapDescriptorFactory.FromResource(Resource.Drawable.me_location_marker);
                backRelativeLayout = FindViewById <RelativeLayout>(Resource.Id.backRelativeLayout);
                back_button        = FindViewById <ImageButton>(Resource.Id.back_button);
                apply_cancelLL     = FindViewById <LinearLayout>(Resource.Id.apply_cancelLL);
                applyTV            = FindViewById <TextView>(Resource.Id.applyTV);
                cancelTV           = FindViewById <TextView>(Resource.Id.cancelTV);
                searchET           = FindViewById <EditText>(Resource.Id.searchET);
                okBn = FindViewById <Button>(Resource.Id.okBn);
                Typeface tf = Typeface.CreateFromAsset(Assets, "Roboto-Regular.ttf");
                FindViewById <TextView>(Resource.Id.headerTV).SetTypeface(tf, TypefaceStyle.Bold);
                applyTV.SetTypeface(tf, TypefaceStyle.Normal);
                cancelTV.SetTypeface(tf, TypefaceStyle.Normal);
                searchET.SetTypeface(tf, TypefaceStyle.Normal);
                okBn.SetTypeface(tf, TypefaceStyle.Normal);
                backRelativeLayout.Click += (s, e) =>
                {
                    OnBackPressed();
                };
                back_button.Click += (s, e) =>
                {
                    OnBackPressed();
                };
                _mapFragment =
                    FragmentManager.FindFragmentByTag("map") as MapFragment;
                if (_mapFragment == null)
                {
                    GoogleMapOptions mapOptions = new GoogleMapOptions()
                                                  .InvokeMapType(GoogleMap.MapTypeNormal)
                                                  .InvokeZoomControlsEnabled(false)
                                                  .InvokeCompassEnabled(true);

                    FragmentTransaction fragTx = FragmentManager.BeginTransaction();
                    _mapFragment = MapFragment.NewInstance(mapOptions);
                    fragTx.Add(Resource.Id.map, _mapFragment, "map");
                    fragTx.Commit();
                }
                _mapFragment.GetMapAsync(this);
                applyTV.Click += delegate
                {
                    edit_city_coord_for_edit.PutString("lat", chosen_lat);
                    edit_city_coord_for_edit.PutString("lng", chosen_lng);
                    edit_city_coord_for_edit.Apply();
                    StartActivity(typeof(ApplyCityEditActivity));
                };
                cancelTV.Click += delegate
                {
                    StartActivity(typeof(UserProfileActivity));
                };
                searchET.TextChanged += (s, e) =>
                {
                    if (!String.IsNullOrEmpty(searchET.Text))
                    {
                        okBn.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        okBn.Visibility = ViewStates.Gone;
                    }
                };
                okBn.Click += delegate
                {
                    if (!String.IsNullOrWhiteSpace(searchET.Text))
                    {
                        //dissmissing keyboard
                        InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                        imm.HideSoftInputFromWindow(searchET.WindowToken, 0);
                        //dissmissing keyboard ENDED

                        new Thread(new ThreadStart(() =>
                        {
                            var geo = new Geocoder(this);

                            var addresses = geo.GetFromLocationName(searchET.Text, 1);

                            RunOnUiThread(() =>
                            {
                                var addressText = FindViewById <TextView>(Resource.Id.searchET);

                                addresses.ToList().ForEach((addr) =>
                                {
                                    LatLng search_location = new LatLng(
                                        Convert.ToDouble(addr.Latitude, (CultureInfo.InvariantCulture)),
                                        Convert.ToDouble(addr.Longitude, (CultureInfo.InvariantCulture)));
                                    CameraPosition.Builder builder_search = CameraPosition.InvokeBuilder();
                                    builder_search.Target(search_location);
                                    builder_search.Zoom(15);
                                    CameraPosition search_cameraPosition = builder_search.Build();
                                    cameraUpdate = CameraUpdateFactory.NewCameraPosition(search_cameraPosition);
                                    _map.MoveCamera(cameraUpdate);

                                    new_coords_descriptor = BitmapDescriptorFactory.FromResource(Resource.Drawable.offline_expert_marker);
                                    if (work_marker != null)
                                    {
                                        work_marker.Remove();
                                    }
                                    edit_city_coord_for_edit    = city_coord_for_edit_prefs.Edit();
                                    apply_cancelLL.Visibility   = ViewStates.Visible;
                                    MarkerOptions markerOptions = new MarkerOptions();
                                    markerOptions.SetPosition(search_location);
                                    markerOptions.SetIcon(new_coords_descriptor);
                                    work_marker       = _map.AddMarker(markerOptions);
                                    work_marker.Title = GetString(Resource.String.work_location);
                                    chosen_lat        = search_location.Latitude.ToString();
                                    chosen_lng        = search_location.Longitude.ToString();
                                });
                            });
                        })).Start();
                    }
                };
            }
            catch
            {
                var available = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(ApplicationContext);
                if (available != 0)
                {
                    Toast.MakeText(this, GetString(Resource.String.install_google_play_services), ToastLength.Long).Show();
                }
                StartActivity(typeof(MainActivity));
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.MapForChooseTourCoords);

            applyChangesBn            = FindViewById <Button>(Resource.Id.applyChangesBn);
            searchBn                  = FindViewById <Button>(Resource.Id.searchBn);
            searchET                  = FindViewById <EditText>(Resource.Id.searchET);
            longTapTV                 = FindViewById <TextView>(Resource.Id.longTapTV);
            applyChangesBn.Visibility = ViewStates.Gone;
            //Button for centering the location of the user
            cenrterPosBn = FindViewById <Button>(Resource.Id.centerPositionBn);

            string   path = "fonts/HelveticaNeueLight.ttf";
            Typeface tf   = Typeface.CreateFromAsset(Assets, path);

            applyChangesBn.Typeface = tf;
            searchBn.Typeface       = tf;
            searchET.Typeface       = tf;
            longTapTV.Typeface      = tf;
            _mapFragment            = FragmentManager.FindFragmentByTag("map") as MapFragment;

            if (_mapFragment == null)
            {
                GoogleMapOptions mapOptions = new GoogleMapOptions()
                                              .InvokeMapType(GoogleMap.MapTypeNormal)
                                              .InvokeZoomControlsEnabled(false)
                                              .InvokeCompassEnabled(true);

                FragmentTransaction fragTx = FragmentManager.BeginTransaction();
                _mapFragment = MapFragment.NewInstance(mapOptions);
                fragTx.Add(Resource.Id.map, _mapFragment, "map");
                fragTx.Commit();

                lat_temp_NEW_start_activity = null;
                lng_temp_NEW_start_activity = null;
            }
            _mapFragment.GetMapAsync(this);

            if (ChangeDestination.changedDestinationIndicator == true)
            {
                if (Tours_detail.searchOrMovieAdapterIndicator != "SearchAdapter")
                {
                    string lat_replaced = ChangeDestination.lat.ToString();
                    string lng_replaced = ChangeDestination.lng.ToString();
                    if (lat_replaced.Contains(","))
                    {
                        lat_replaced = ChangeDestination.lat.ToString().Replace(',', '.');
                    }
                    if (lng_replaced.Contains(","))
                    {
                        lng_replaced = ChangeDestination.lng.ToString().Replace(',', '.');
                    }

                    LatLng target_location = new LatLng(Convert.ToDouble(lat_replaced, (CultureInfo.InvariantCulture)),
                                                        Convert.ToDouble(lng_replaced, (CultureInfo.InvariantCulture)));
                    CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                    target_builder.Target(target_location);
                    target_builder.Zoom(15);
                    CameraPosition target_cameraPosition = target_builder.Build();
                    cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                }
                else if (Tours_detail.searchOrMovieAdapterIndicator == "SearchAdapter")
                {
                    foreach (var o in SearchAdapter.experiencesStatic)
                    {
                        if (!String.IsNullOrWhiteSpace(o.lat) && !String.IsNullOrWhiteSpace(o.lng))
                        {
                            foreach (char c in o.lat)
                            {
                                if (c == ',')
                                {
                                    lat_tmp += ".";
                                }
                                else
                                {
                                    lat_tmp += c;
                                }
                            }
                            foreach (char c in o.lng)
                            {
                                if (c == ',')
                                {
                                    lng_tmp += ".";
                                }
                                else
                                {
                                    lng_tmp += c;
                                }
                            }
                            lat_search_target_users_position = Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)) + 0.005;
                            lng_search_target_users_position = Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture)) + 0.005;

                            lat_tmp = "";
                            lng_tmp = "";
                        }
                    }
                    LatLng target_location = new LatLng(lat_search_target_users_position, lng_search_target_users_position);
                    CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                    target_builder.Target(target_location);
                    target_builder.Zoom(15);
                    CameraPosition target_cameraPosition = target_builder.Build();
                    cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                }
                _mapFragment.GetMapAsync(this);
            }
            // _mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment;


            placesOfInterstInfo.places_of_interest();
            if (ChangeDestination.changedDestinationIndicator == true)
            {
            }
            if (ChangeDestination.changedDestinationIndicator != true)
            {
                if (Tours_detail.searchOrMovieAdapterIndicator == "MovieAdapter" || String.IsNullOrWhiteSpace(Tours_detail.searchOrMovieAdapterIndicator))
                {
                    string lat_replaced = NEWstartActivity.lat;
                    string lng_replaced = NEWstartActivity.lon;
                    if (lat_replaced.Contains(","))
                    {
                        lat_replaced = NEWstartActivity.lat.Replace(',', '.');
                    }
                    if (lng_replaced.Contains(","))
                    {
                        lng_replaced = NEWstartActivity.lon.Replace(',', '.');
                    }
                    lat_temp_NEW_start_activity = lat_replaced;
                    lng_temp_NEW_start_activity = lng_replaced;

                    /*//replacing dot instead of comma in coordinates
                     * foreach (char c in Activities.NEWstartActivity.lat)
                     * {
                     *  if (c == ',')
                     *  {
                     *      lat_temp_NEW_start_activity += ".";
                     *  }
                     *  else
                     *  {
                     *      lat_temp_NEW_start_activity += c;
                     *  }
                     * }
                     * foreach (char c in Activities.NEWstartActivity.lon)
                     * {
                     *  if (c == ',')
                     *  {
                     *      lng_temp_NEW_start_activity += ".";
                     *  }
                     *  else
                     *  {
                     *      lng_temp_NEW_start_activity += c;
                     *  }
                     * }
                     * //replacing dot instead of comma in coordinates ENDED*/

                    //LatLng location = new LatLng(Convert.ToDouble(Activities.NEWstartActivity.lat), Convert.ToDouble(Activities.NEWstartActivity.lon));
                    try
                    {
                        LatLng location = new LatLng(Convert.ToDouble(lat_temp_NEW_start_activity, (CultureInfo.InvariantCulture)),
                                                     Convert.ToDouble(lng_temp_NEW_start_activity, (CultureInfo.InvariantCulture)));

                        /*lat_temp_NEW_start_activity = "";
                        *  lng_temp_NEW_start_activity = "";*/
                        CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                        builder.Target(location);
                        builder.Zoom(15);

                        /*builder.Bearing(155);
                         * builder.Tilt(65);*/
                        CameraPosition cameraPosition = builder.Build();
                        cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                        _mapFragment.GetMapAsync(this);
                    }
                    catch { }
                }
                else if (Tours_detail.searchOrMovieAdapterIndicator == "SearchAdapter")
                {
                    foreach (var o in SearchAdapter.experiencesStatic)
                    {
                        if (!String.IsNullOrWhiteSpace(o.lat) && !String.IsNullOrWhiteSpace(o.lng))
                        {
                            foreach (char c in o.lat)
                            {
                                if (c == ',')
                                {
                                    lat_tmp += ".";
                                }
                                else
                                {
                                    lat_tmp += c;
                                }
                            }
                            foreach (char c in o.lng)
                            {
                                if (c == ',')
                                {
                                    lng_tmp += ".";
                                }
                                else
                                {
                                    lng_tmp += c;
                                }
                            }

                            lat_search_target_users_position = Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)) + 0.005;
                            lng_search_target_users_position = Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture)) + 0.005;

                            lat_tmp = "";
                            lng_tmp = "";
                        }
                    }
                    //centring camera on target location
                    LatLng target_location = new LatLng(lat_search_target_users_position, lng_search_target_users_position);
                    CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                    target_builder.Target(target_location);
                    target_builder.Zoom(15);
                    CameraPosition target_cameraPosition = target_builder.Build();
                    cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                    _mapFragment.GetMapAsync(this);
                    //centring camera on target location ENDED
                }
            }
            int p;

            p = 10;
            if (ChangeDestination.changedDestinationIndicator == true)
            {
                /*if (Tours_detail.searchOrMovieAdapterIndicator != "SearchAdapter")
                 * {
                 *  LatLng target_location = new LatLng(Convert.ToDouble(ChangeDestination.lat, (CultureInfo.InvariantCulture)),
                 *      Convert.ToDouble(ChangeDestination.lng, (CultureInfo.InvariantCulture)));
                 *  CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                 *  target_builder.Target(target_location);
                 *  target_builder.Zoom(15);
                 *  CameraPosition target_cameraPosition = target_builder.Build();
                 *  cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                 * }
                 * else if (Tours_detail.searchOrMovieAdapterIndicator == "SearchAdapter")
                 * {
                 *  foreach (var o in SearchAdapter.experiencesStatic)
                 *  {
                 *      if (!String.IsNullOrWhiteSpace(o.lat) && !String.IsNullOrWhiteSpace(o.lng))
                 *      {
                 *          foreach (char c in o.lat)
                 *          {
                 *              if (c == ',')
                 *              {
                 *                  lat_tmp += ".";
                 *              }
                 *              else
                 *              {
                 *                  lat_tmp += c;
                 *              }
                 *          }
                 *          foreach (char c in o.lng)
                 *          {
                 *              if (c == ',')
                 *              {
                 *                  lng_tmp += ".";
                 *              }
                 *              else
                 *              {
                 *                  lng_tmp += c;
                 *              }
                 *          }
                 *          lat_search_target_users_position = Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)) + 0.005;
                 *          lng_search_target_users_position = Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture)) + 0.005;
                 *
                 *          lat_tmp = "";
                 *          lng_tmp = "";
                 *      }
                 *  }
                 *  LatLng target_location = new LatLng(lat_search_target_users_position, lng_search_target_users_position);
                 *  CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                 *  target_builder.Target(target_location);
                 *  target_builder.Zoom(15);
                 *  CameraPosition target_cameraPosition = target_builder.Build();
                 *  cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                 * }
                 * _mapFragment.GetMapAsync(this);*/
            }

            searchBn.Click += delegate
            {
                if (!String.IsNullOrWhiteSpace(searchET.Text))
                {
                    //dissmissing keyboard
                    InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                    imm.HideSoftInputFromWindow(searchET.WindowToken, 0);
                    //dissmissing keyboard ENDED

                    new Thread(new ThreadStart(() =>
                    {
                        var geo = new Geocoder(this);

                        var addresses = geo.GetFromLocationName(searchET.Text, 1);

                        RunOnUiThread(() =>
                        {
                            var addressText = FindViewById <TextView>(Resource.Id.searchET);

                            addresses.ToList().ForEach((addr) =>
                            {
                                LatLng search_location = new LatLng(Convert.ToDouble(addr.Latitude, (CultureInfo.InvariantCulture)),
                                                                    Convert.ToDouble(addr.Longitude, (CultureInfo.InvariantCulture)));
                                CameraPosition.Builder builder_search = CameraPosition.InvokeBuilder();
                                builder_search.Target(search_location);
                                builder_search.Zoom(15);
                                CameraPosition search_cameraPosition = builder_search.Build();
                                cameraUpdate = CameraUpdateFactory.NewCameraPosition(search_cameraPosition);
                                _mapFragment.GetMapAsync(this);
                            });
                        });
                    })).Start();
                }
            };

            applyChangesBn.Click += delegate
            {
                if (addOrEditTourIndicator == "edit")
                {
                    OnBackPressed();
                }
                else if (addOrEditTourIndicator == "add")
                {
                    StartActivity(typeof(RecyclerViewSampl.AddNewTourActivity));
                }
            };


            cenrterPosBn.Click += (s, e) =>
            {
                if (ChangeDestination.changedDestinationIndicator == false)
                {
                    if (Tours_detail.searchOrMovieAdapterIndicator == "MovieAdapter" || String.IsNullOrWhiteSpace(Tours_detail.searchOrMovieAdapterIndicator))
                    {
                        LatLng location = new LatLng(Convert.ToDouble(lat_temp_NEW_start_activity, (CultureInfo.InvariantCulture)),
                                                     Convert.ToDouble(lng_temp_NEW_start_activity, (CultureInfo.InvariantCulture)));

                        /*lat_temp_NEW_start_activity = "";
                        *  lng_temp_NEW_start_activity = "";*/
                        CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                        builder.Target(location);
                        builder.Zoom(15);

                        /*builder.Bearing(155);
                         * builder.Tilt(65);*/
                        CameraPosition cameraPosition = builder.Build();
                        cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                        _mapFragment.GetMapAsync(this);
                    }
                    else if (Tours_detail.searchOrMovieAdapterIndicator == "SearchAdapter")
                    {
                        //centring camera on target location
                        LatLng target_location = new LatLng(lat_search_target_users_position, lng_search_target_users_position);
                        CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                        target_builder.Target(target_location);
                        target_builder.Zoom(15);
                        CameraPosition target_cameraPosition = target_builder.Build();
                        cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                        _mapFragment.GetMapAsync(this);
                        //centring camera on target location ENDED
                    }
                }
                else if (ChangeDestination.changedDestinationIndicator == true)
                {
                    if (Tours_detail.searchOrMovieAdapterIndicator == "MovieAdapter")
                    {
                        LatLng target_location = new LatLng(Convert.ToDouble(ChangeDestination.lat, (CultureInfo.InvariantCulture)),
                                                            Convert.ToDouble(ChangeDestination.lng, (CultureInfo.InvariantCulture)));
                        CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                        target_builder.Target(target_location);
                        target_builder.Zoom(15);
                        CameraPosition target_cameraPosition = target_builder.Build();
                        cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                        _mapFragment.GetMapAsync(this);
                    }
                    else if (Tours_detail.searchOrMovieAdapterIndicator == "SearchAdapter")
                    {
                        //centring camera on target location
                        LatLng target_location = new LatLng(lat_search_target_users_position, lng_search_target_users_position);
                        CameraPosition.Builder target_builder = CameraPosition.InvokeBuilder();
                        target_builder.Target(target_location);
                        target_builder.Zoom(15);
                        CameraPosition target_cameraPosition = target_builder.Build();
                        cameraUpdate = CameraUpdateFactory.NewCameraPosition(target_cameraPosition);
                        _mapFragment.GetMapAsync(this);
                        //centring camera on target location ENDED
                    }
                }
            };
        }
Beispiel #19
0

        async Task<string> GeocodeToConsoleAsync(string address)
        {
            var geo = new Geocoder(this);

            var addresses = geo.GetFromLocationName(address, 1);
            RunOnUiThread(() =>
            {
                addresses.ToList().ForEach((addr) =>
                {
                    SetWorkMarker(addr);
                });
            });
            return "";
        }

        void SetWorkMarker(Android.Locations.Address addr)
Beispiel #20
0
        //   Massachusetts lat/long = 42.37419, -71.120639
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            var      but         = FindViewById <Android.Widget.Button>(Resource.Id.button);
            var      but1        = FindViewById <Android.Widget.Button>(Resource.Id.button1);
            var      but2        = FindViewById <Android.Widget.Button>(Resource.Id.button2);
            EditText house       = FindViewById <Android.Widget.EditText>(Resource.Id.houseNo);
            EditText ave         = FindViewById <Android.Widget.EditText>(Resource.Id.street);
            EditText city        = FindViewById <Android.Widget.EditText>(Resource.Id.city);
            EditText state       = FindViewById <Android.Widget.EditText>(Resource.Id.state);
            EditText zip         = FindViewById <Android.Widget.EditText>(Resource.Id.zipCode);
            EditText lat         = FindViewById <Android.Widget.EditText>(Resource.Id.lat);
            EditText lon         = FindViewById <Android.Widget.EditText>(Resource.Id.lon);
            TextView addressText = FindViewById <TextView>(Resource.Id.street);

            /**********************************************************************************/
            but.Click += async(sender, e) =>
            {
                Context con = this;
                if ((house.Text == "") && (city.Text == "") && (state.Text == ""))
                {    // get address from lat/long
                    double theLatitude;
                    double theLongitude;
                    theLatitude  = Convert.ToDouble(lat.Text);
                    theLongitude = Convert.ToDouble(lon.Text);
                    var             geo       = new Geocoder(this);
                    IList <Address> addresses = geo.GetFromLocation(theLatitude, theLongitude, 1);
                    await MyAsyncMethod();

                    if (addresses.Any())
                    {
                        UpdateAddressFields(addresses.First());
                    }
                    else
                    {
                        Toast.MakeText(this.ApplicationContext, "Did not find address", ToastLength.Short).Show();
                    }
                }
                else   // get lat/long from address
                {
                    string          addr = house.Text + " " + ave.Text + " " + city.Text + " " + state.Text + " " + zip.Text;
                    IList <Address> addresses;
                    var             geo = new Geocoder(con);
                    addresses = geo.GetFromLocationName(addr, 1);
                    await MyAsyncMethod();

                    if (!addresses.Any())
                    {
                        Toast.MakeText(this.ApplicationContext, "Did not find LatLong", ToastLength.Short).Show();
                    }
                    double a = addresses.First().Latitude;
                    lat.Text = a.ToString();
                    double b = addresses.First().Longitude;
                    lon.Text = b.ToString();
                }
            };
            /**************************************************************************************/
            but2.Click += (sender, e) =>
            {
                house.Text = "";
                ave.Text   = "";
                city.Text  = "";
                state.Text = "";
                zip.Text   = "";
            };
            /**************************************************************************************/
            but1.Click += (sender, e) =>
            {
                Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
            };
            /**************************************************************************************/
            void UpdateAddressFields(Address addr)
            {
                house.Text = addr.FeatureName;
                state.Text = addr.AdminArea;
                zip.Text   = addr.PostalCode;
                ave.Text   = addr.Thoroughfare;
                city.Text  = addr.Locality;
            }
        }
Beispiel #21
0
        // Get lattitude and longitude of current location
        // http://developer.xamarin.com/recipes/android/os_device_resources/gps/get_current_device_location/



        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            locationText = FindViewById <TextView> (Resource.Id.locationText);
            radiusText   = FindViewById <TextView> (Resource.Id.radiusText);
            distanceText = FindViewById <TextView> (Resource.Id.distanceText);
            var button = FindViewById <Button> (Resource.Id.button);

            // Initialize location manager

            InitializeLocationManager();

            locationManager = (LocationManager)GetSystemService(LocationService);



            // Pass the specified destination and radius to program by clicking button

            button.Click += (sender, e) => {
                // Use Geocoder to get longitude and lattitude for destination
                // http://developer.xamarin.com/recipes/android/os_device_resources/geocoder/geocode_an_address/

                var geo = new Geocoder(this);

                var addresses = geo.GetFromLocationName(locationText.Text, 1);

                Address endLocation = addresses.ToList().FirstOrDefault();

                double endLat        = endLocation.Latitude;
                double endLon        = endLocation.Longitude;
                double radius        = Convert.ToDouble(radiusText.Text) * 1609.34;        // in meters
                float  radius_meters = (float)radius;

                destination           = new Location(locationProvider);
                destination.Latitude  = endLat;
                destination.Longitude = endLon;

                locationManager.RequestLocationUpdates(locationProvider, 0, 0, this);

                Intent        intent          = new Intent(PROX_ALERT_INTENT);
                PendingIntent proximityIntent = PendingIntent.GetBroadcast(this, 0, intent, 0);

                locationManager.AddProximityAlert(endLat, endLon, radius_meters, -1, proximityIntent);

                IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
                RegisterReceiver(new ProximityIntentReceiver(), filter);



                /*
                 *
                 * // Calculate the distance between current address and the input address
                 * // http://androidapi.xamarin.com/index.aspx?link=M%3AAndroid.Locations.Location.DistanceBetween(System.Double%2CSystem.Double%2CSystem.Double%2CSystem.Double%2CSystem.Single%5B%5D)
                 *
                 * float[] list = new float[1];
                 *
                 * Location.DistanceBetween(currentLat, currentLon, endLat, endLon, list);
                 *
                 * // Show distance between current address and destination in the text field
                 *
                 * distance = list[0]/1000;
                 * double distance_round = Math.Round(Convert.ToDouble(distance), 3);
                 * distanceText.Text = distance_round.ToString();
                 *
                 * // Console.WriteLine ("distance: " + distance);
                 *
                 * // Alert if the distance is smaller than the specified radius
                 *
                 * if (distance_round <= Convert.ToDouble(radiusText.Text))
                 * {
                 *      // if choose screen alert
                 *      // alert(sender, e);
                 *
                 *      // use notification
                 *      // http://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/local_notifications_in_android/
                 *
                 *      // instantiate the builder and set notification elements
                 *      Notification.Builder builder = new Notification.Builder(this)
                 *              .SetAutoCancel(true)
                 *              .SetContentTitle("Alert")
                 *              .SetContentText("You are within " + radiusText.Text + " km to your destination")
                 *              .SetDefaults(NotificationDefaults.Sound)
                 *              .SetSmallIcon(Resource.Drawable.logo);
                 *
                 *      // build the notification
                 *      Notification notification = builder.Build();
                 *
                 *      // get the notification manager
                 *      NotificationManager notificationManager = GetSystemService (Context.NotificationService) as NotificationManager;
                 *
                 *      // publish the notification
                 *      const int notificationId = 0;
                 *      notificationManager.Notify(notificationId, notification);
                 *
                 * } */
            };
        }
Beispiel #22
0
        private void searchNearMe(object sender, EventArgs e)
        {
            MainActivity MAct = (MainActivity)MainActivity.activity;
            MainActivity act  = (MainActivity)this.Activity;
            string       data = GetData();

            Button nearButton = (Button)act.FindViewById(Resource.Id.nearMe);

            nearButton.Enabled = false;

            if (MAct.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted)
            {
                RequestPermissions(new string[] { Android.Manifest.Permission.AccessCoarseLocation, Android.Manifest.Permission.AccessFineLocation }, 0);
            }

            JArray                jsonArray    = JArray.Parse(data);
            List <string>         searched_Loc = new List <string>();
            List <AddressLocator> mAddresses   = new List <AddressLocator>();
            AddressLocator        tempAddress;



            for (int i = 0; i < jsonArray.Count; i++)
            {
                JToken json = jsonArray[i];
                if (act.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) == (int)Android.Content.PM.Permission.Granted)
                {
                    Geocoder        coder   = new Geocoder(act);
                    IList <Address> address = new List <Address>();


                    address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                    float lon = (float)address.ElementAt(0).Longitude;
                    float lat = (float)address.ElementAt(0).Latitude;

                    tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                    mAddresses.Add(tempAddress);


                    userLocationObtained = true;
                }
                else
                {
                    Toast.MakeText(MainActivity.activity, "Cannot Calculate User Location. Please allow for the application to use location permissions.", ToastLength.Long).Show();
                }
            }

            if (userLocationObtained)
            {
                //calculate distances
                CalculateAddressDistance(mAddresses);
                //sort distances
                mAddresses.Sort();

                for (int x = 0; x < mAddresses.Count; x++)
                {
                    if (mAddresses.ElementAt(x).Distance < 15.00)
                    {
                        searched_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                    }
                }
            }

            mTv = act.FindViewById <ListView>(Resource.Id.searchResults);
            ArrayAdapter <string> arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, searched_Loc);

            mTv.Adapter = arrayAdapter;
            mTv.SetFooterDividersEnabled(true);
            mTv.SetHeaderDividersEnabled(true);
            nearButton.Enabled = true;
        }
Beispiel #23
0
        private async void submitQueryListener(object sender, SearchView.QueryTextSubmitEventArgs e)
        {
            MainActivity act        = (MainActivity)this.Activity;
            SearchView   searchView = (SearchView)act.FindViewById(Resource.Id.searchView1);
            string       input      = e.Query;

            searchView.SetIconifiedByDefault(true);
            searchView.OnActionViewCollapsed();
            searchView.Focusable = false;

            //Ping database by name
            string data = GetData();

            JArray        jsonArray    = JArray.Parse(data);
            List <string> searched_Loc = new List <string>();
            List <string> similar_Loc  = new List <string>();

            string debugMe    = "";
            string tempinput  = input;
            string inputBlock = tempinput;

            tempinput = RemoveSpecialCharacters(tempinput);
            tempinput = tempinput.Replace(" ", System.String.Empty);

            AddressLocator        tempAddress;
            List <AddressLocator> mAddresses = new List <AddressLocator>();

            for (int i = 0; i < jsonArray.Count; i++)
            {
                JToken json = jsonArray[i];
                string temp = (string)json["name"];
                temp = RemoveSpecialCharacters(temp);
                temp = temp.Replace(" ", System.String.Empty);
                if (((string)json["name"]).Equals(input, StringComparison.InvariantCultureIgnoreCase) || temp.Equals(tempinput, StringComparison.InvariantCultureIgnoreCase))
                {
                    //Location stuff - make sure user location permissions were give
                    if (act.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) == (int)Android.Content.PM.Permission.Granted)
                    {
                        Geocoder        coder   = new Geocoder(act);
                        IList <Address> address = new List <Address>();


                        address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                        float lon = (float)address.ElementAt(0).Longitude;
                        float lat = (float)address.ElementAt(0).Latitude;

                        tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                        mAddresses.Add(tempAddress);


                        userLocationObtained = true;
                    }
                    else // if not, grab list like before.
                    {
                        searched_Loc.Add(((string)json["name"]) + ": " + ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]));
                    }
                }
            }

            if (userLocationObtained)
            {
                //calculate distances
                CalculateAddressDistance(mAddresses);
                //sort distances
                mAddresses.Sort();

                for (int x = 0; x < mAddresses.Count; x++)
                {
                    searched_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                }
            }

            for (int j = 0; j < searched_Loc.Count; j++)
            {
                debugMe += searched_Loc[j];
                debugMe += "\n";
            }

            if (searched_Loc.Count == 0)
            {
                for (int i = 0; i < jsonArray.Count; i++)
                {
                    JToken json      = jsonArray[i];
                    bool   wordMatch = false;
                    string temp      = (string)json["name"];

                    string[] outputBlock = temp.Split(" ");

                    temp = RemoveSpecialCharacters(temp);
                    temp = temp.Replace(" ", System.String.Empty);

                    wordMatch = InputsMatch(inputBlock.ToLower(), outputBlock);

                    if ((tempinput.StartsWith(temp.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) || wordMatch) && !userLocationObtained)
                    {
                        similar_Loc.Add(((string)json["name"]) + ": " + ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]));
                    }
                    else if ((tempinput.StartsWith(temp.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) || wordMatch) && userLocationObtained)
                    {
                        Geocoder        coder   = new Geocoder(act);
                        IList <Address> address = new List <Address>();


                        address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                        float lon = (float)address.ElementAt(0).Longitude;
                        float lat = (float)address.ElementAt(0).Latitude;

                        tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                        mAddresses.Add(tempAddress);
                    }
                }
                if (userLocationObtained)
                {
                    //calculate distances
                    CalculateAddressDistance(mAddresses);
                    //sort distances
                    mAddresses.Sort();

                    for (int x = 0; x < mAddresses.Count; x++)
                    {
                        similar_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                    }
                }
            }

            mTv = act.FindViewById <ListView>(Resource.Id.searchResults);
            ArrayAdapter <string> arrayAdapter;

            if (searched_Loc.Count == 0 && similar_Loc.Count == 0)
            {
                Toast.MakeText(MainActivity.activity, "There were no results for that Location.", ToastLength.Long).Show();
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, similar_Loc);
            }
            else if (searched_Loc.Count == 0)
            {
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, similar_Loc);
            }
            else
            {
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, searched_Loc);
            }

            mTv.Adapter = arrayAdapter;
            mTv.SetFooterDividersEnabled(true);
            mTv.SetHeaderDividersEnabled(true);
        }