示例#1
0
        public async Task <GoogleDirectionClass> getIt()
        {
            GoogleDirectionClass g = await _googleMapService.FnDrawPath("aalborg", "herning");

            System.Diagnostics.Debug.WriteLine(g.routes.Count);
            return(g);
        }
示例#2
0
 public GoogleDirectionClass GetDirectionsData(SharedPartnerDataModels.Bounds2 bounds)
 {
     //Initializer and  query partner server
     using (PartnerServiceRequestProcessor webRequest = new PartnerServiceRequestProcessor(
                new Directions(Application.Context.Resources.GetString(RidersApp.Resource.String.PlacesAPIKey), new SharedPartnerDataModels.Location(bounds.northeast), new SharedPartnerDataModels.Location(bounds.southwest))))
     {
         Exception            exception  = webRequest.GetPatnerServiceQueryException();
         GoogleDirectionClass directions = null;
         if (exception is null)
         {
             directions = (GoogleDirectionClass)webRequest.ProcessPartnerServiceQueryResult();
         }
         return(directions);
     }
 }
示例#3
0
        void FnSetDirectionQuery(GoogleDirectionClass objRoutes)
        {
            //objRoutes.routes.Count  --may be more then one
            if (objRoutes.routes.Count > 0)
            {
                string encodedPoints = objRoutes.routes[0].overview_polyline.points;

                var lstDecodedPoints = FnDecodePolylinePoints(encodedPoints);
                //convert list of location point to array of latlng type
                var latLngPoints = new LatLng[lstDecodedPoints.Count];
                int index        = 0;
                foreach (var loc in lstDecodedPoints)
                {
                    latLngPoints[index++] = new LatLng(loc.lat, loc.lng);
                }

                var polylineoption = new PolylineOptions();
                polylineoption.InvokeColor(Android.Graphics.Color.Red);
                polylineoption.Geodesic(true);
                polylineoption.Add(latLngPoints);
                RunOnUiThread(() =>
                              map.AddPolyline(polylineoption));
            }
        }
示例#4
0
        public object Search(string from, string to, int radius)
        {
            HttpClient webservice = new HttpClient();

            string url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + from + "&destination=" + to + "&key=AIzaSyDIR_Gt9qJxpvTgCr9z-wfCVFTKPjGs_8w";

            //Debug.WriteLine(postData);

            HttpResponseMessage response = webservice.GetAsync(url).Result;

            /*  */
            GoogleDirectionClass objRoutes = JsonConvert.DeserializeObject <GoogleDirectionClass>(response.Content.ReadAsStringAsync().Result);

            if (objRoutes.routes.Count > 0)
            {
                string encodedPoints = objRoutes.routes[0].overview_polyline.points;

                List <Models.Location> lstDecodedPoints = FnDecodePolylinePoints(encodedPoints);
                //convert list of location point to array of latlng type
                LatLngNew[]  latLngPoints = new LatLngNew[lstDecodedPoints.Count];
                Coordinate[] ss           = new Coordinate[lstDecodedPoints.Count];

                int index = 0;
                foreach (Models.Location loc in lstDecodedPoints)
                {
                    latLngPoints[index] = new LatLngNew(loc.lat, loc.lng);
                    ss[index]           = new Coordinate(loc.lat, loc.lng);
                    index++;
                }
                //TODO: do bd....
                double searchRadios = (double)radius / 37;

                var lineString   = new LineString(ss);
                var buffer       = VariableWidthBuffer.Buffer(lineString, searchRadios, searchRadios);
                var bArray       = buffer.Coordinates;
                var bArrayLength = buffer.Coordinates.Length;
                double[,] pArray = new double[bArrayLength, 2];
                for (int i = 0; i < bArrayLength; i++)
                {
                    pArray[i, 0] = bArray[i].X;
                    pArray[i, 1] = bArray[i].Y;
                }
                GoogleReturnObj returnObj = new GoogleReturnObj()
                {
                    PolyLinePoints = latLngPoints.ToList(),
                    Source         = new Area()
                    {
                        Pos = new LatLngNew(objRoutes.routes[0].legs[0].start_location.lat, objRoutes.routes[0].legs[0].start_location.lng), Name = from
                    },
                    Destination = new Area()
                    {
                        Pos = new LatLngNew(objRoutes.routes[0].legs[0].end_location.lat, objRoutes.routes[0].legs[0].end_location.lng), Name = to
                    },
                    Points = pArray
                };

                var s = new { convert = buffer, coordinates = latLngPoints, coords = buffer.Coordinates.Select(x => new LatLngNew(x.X, x.Y)), darr = buffer.Coordinates.Select(d => new double[] { d.X, d.Y }) };
                return(returnObj);
            }
            return(null);
        }
示例#5
0
        public List <Models.Location> decodePolyPoints(GoogleDirectionClass objRoutes)
        {
            var result = _googleMapService.FnDecodePolylinePoints(objRoutes.routes[0].overview_polyline.points);

            return(result);
        }
    public object ProcessPartnerServiceQueryResults(string result)
    {
        GoogleDirectionClass JsonObject = JsonConvert.DeserializeObject <GoogleDirectionClass>(result);

        return(JsonObject);
    }