Exemple #1
0
        //function to decode,encoded SharedGoogleDataModels.Location points
        public static List <SharedPartnerDataModels.Location> locDecodePoly(string encoded)
        {
            List <SharedPartnerDataModels.Location> poly = new List <SharedPartnerDataModels.Location>();
            int index = 0, len = encoded.Length;
            int lat = 0, lng = 0;

            while (index < len)
            {
                int b, shift = 0, result = 0;
                do
                {
                    b       = encoded[index++] - 63;
                    result |= (b & 0x1f) << shift;
                    shift  += 5;
                } while (b >= 0x20);
                int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
                lat   += dlat;
                shift  = 0;
                result = 0;
                do
                {
                    b       = encoded[index++] - 63;
                    result |= (b & 0x1f) << shift;
                    shift  += 5;
                } while (b >= 0x20);
                int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
                lng += dlng;
                SharedPartnerDataModels.Location p = new SharedPartnerDataModels.Location((((double)lat / 1E5)),
                                                                                          (((double)lng / 1E5)));
                poly.Add(p);
            }
            return(poly);
        }
Exemple #2
0
        //var geo = new Geocoder(ctx);//var sourceAddresss = await geo.GetFromLocationNameAsync(sourceLocationName, 1);
        //sourceAddress.ToList().ForEach((addr) => { latLngSource = new LatLng(addr.Latitude, addr.Longitude); });
        //var destAddress = await geo.GetFromLocationNameAsync(destinationLocationName, 1);
        //destAddress.ToList().ForEach((addr) => { latLngDestination = new LatLng(addr.Latitude, addr.Longitude); });

        //using google geocode api to convert location to latlng
        //string strGeoCode = string.Format ("address={0}",strLocation);
        //string strGeoCodeFullURL = string.Format (Constants.strGeoCodingUrl,strGeoCode);
        //
        //string strResult= FnHttpRequestOnMainThread(strGeoCodeFullURL);
        //if ( strResult != Constants.strException )
        //{
        //		var objGeoCodeJSONClass= JsonConvert.DeserializeObject<GeoCodeJSONClass> (strResult);
        //		Position= new LatLng ( objGeoCodeJSONClass.results [0].geometry.location.lat , objGeoCodeJSONClass.results [0].geometry.location.lng );
        //}
        //function to decode,encoded points

        public static List <SharedPartnerDataModels.Location> FnDecodePolylinePoints(string encodedPoints)
        {
            if (string.IsNullOrEmpty(encodedPoints))
            {
                return(null);
            }
            var poly = new List <SharedPartnerDataModels.Location>();

            char[] polylinechars = encodedPoints.ToCharArray();
            int    index         = 0;

            int currentLat = 0;
            int currentLng = 0;
            int next5bits;
            int sum;
            int shifter;

            while (index < polylinechars.Length)
            {
                // calculate next latitude
                sum     = 0;
                shifter = 0;
                do
                {
                    next5bits = (int)polylinechars[index++] - 63;
                    sum      |= (next5bits & 31) << shifter;
                    shifter  += 5;
                } while (next5bits >= 32 && index < polylinechars.Length);

                if (index >= polylinechars.Length)
                {
                    break;
                }

                currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

                //calculate next longitude
                sum     = 0;
                shifter = 0;
                do
                {
                    next5bits = (int)polylinechars[index++] - 63;
                    sum      |= (next5bits & 31) << shifter;
                    shifter  += 5;
                } while (next5bits >= 32 && index < polylinechars.Length);

                if (index >= polylinechars.Length && next5bits >= 32)
                {
                    break;
                }

                currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
                SharedPartnerDataModels.Location p = new SharedPartnerDataModels.Location();
                p.lat = Convert.ToDouble(currentLat) / 100000.0;
                p.lng = Convert.ToDouble(currentLng) / 100000.0;
                poly.Add(p);
            }
            return(poly);
        }
Exemple #3
0
        //Reverse geocode : convert Locaton to name
        public async Task <Address> ReverseGeoCode(MainActivity mainActivity, Context ctx, SharedPartnerDataModels.Location loc)
        {
            Geocoder        geocoder    = new Geocoder(ctx);
            IList <Address> addressList = await geocoder.GetFromLocationAsync(loc.lat, loc.lng, 5);

            Address address = addressList.FirstOrDefault();

            return(address);
        }