Ejemplo n.º 1
0
        public void UpdatePolyLinePos(bool init, LatLng pos = null)
        {
            if (targetLine != null)
            {
                targetLine.Remove();
                targetLine.Dispose();
            }
            var polylineOptions = new PolylineOptions();

            polylineOptions.Clickable(true);
            polylineOptions.InvokeJointType(JointType.Round);//don't see the difference
            polylineOptions.InvokeWidth(10f);
            polylineOptions.InvokeColor(0x664444FF);

            int       i         = 0;
            CustomMap customMap = (CustomMap)this.Element;

            if (customMap != null)
            {
                foreach (var position in customMap.RouteCoordinates)
                {
                    if (i == 1 && !init && pos != null)
                    {
                        polylineOptions.Add(pos);
                    }
                    else
                    {
                        polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                    }

                    i++;
                }
                targetLine = map.AddPolyline(polylineOptions);
            }
        }
Ejemplo n.º 2
0
        private async void GetRutas(int id_mandado)
        {
            List <Manboss_mandados_ruta> rutas = await core.GetRutas(id_mandado);

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (Manboss_mandados_ruta ruta in rutas)
            {
                markerOpt1 = new MarkerOptions();
                LatLng lugar = new LatLng(ruta.Latitud, ruta.Longitud);
                builder.Include(lugar);
                markerOpt1.SetPosition(lugar);
                markerOpt1.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.mandado));
                _map.AddMarker(markerOpt1);
            }
            //Mover camera
            LatLngBounds bounds       = builder.Build();
            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 300);

            _map.MoveCamera(cameraUpdate);
            //Dibujar ruta
            List <Manboss_repartidores_ubicaciones> ubicaciones = await core.GetUbicaciones(id_mandado);

            var polylineOptions = new PolylineOptions();

            polylineOptions.InvokeColor(0x6604B7FF);
            foreach (var position in rutas)
            {
                polylineOptions.Add(new LatLng(position.Latitud, position.Longitud));
            }
            foreach (var position in ubicaciones)
            {
                polylineOptions.Add(new LatLng(position.latitud, position.longitud));
            }
            _map.AddPolyline(polylineOptions);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draw main direction line
        /// </summary>
        /// <param name="angle"></param>
        public void DrawDirection(double angle)
        {
            if (is_initialized == false)
            {
                return;
            }

            GlobalCoordinates stop_geo = get_line_position(angle);

            try
            {
                if (MainLine != null)
                {
                    MainLine.Remove();
                    PolylineOptions linePoints = new PolylineOptions();
                    linePoints.Add(ConvertPos(UserPosition));
                    linePoints.Add(ConvertPos(stop_geo));
                    MainLine = googleMap.AddPolyline(linePoints);
                }
                else
                {
                    PolylineOptions linePoints = new PolylineOptions();
                    linePoints.Add(ConvertPos(UserPosition));
                    linePoints.Add(ConvertPos(stop_geo));
                    MainLine = googleMap.AddPolyline(linePoints);
                }
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------------
        // MAP DRAWING METHODS
        //--------------------------------------------------------------------

        private void AddPolyline(GeoLocation start, GeoLocation end)
        {
            PolylineOptions rectOptions = new PolylineOptions();

            rectOptions.Add(new LatLng(start.Latitude, start.Longitude));
            rectOptions.Add(new LatLng(end.Latitude, end.Longitude));
            Polyline polyline = map.AddPolyline(rectOptions);

            mapPolylines.Add(polyline);
        }
Ejemplo n.º 5
0
        private void DrawPolylineSegment(PolylineSegment polylineSegment, int colorInt)
        {
            var polylineOptions = new PolylineOptions();

            polylineOptions.InvokeColor(colorInt);

            polylineOptions.Add(new LatLng(polylineSegment.SnappedPointStart.Position.Latitude, polylineSegment.SnappedPointStart.Position.Longitude));
            polylineOptions.Add(new LatLng(polylineSegment.SnappedPointEnd.Position.Latitude, polylineSegment.SnappedPointEnd.Position.Longitude));

            NativeMap.AddPolyline(polylineOptions);
        }
Ejemplo n.º 6
0
        private void LoadTrailPath(string start, string end, string path)
        {
            string[] pathCoords = path.Split(';');
            string[] latlng     = start.Split(',');

            double latitude  = 0;
            double longitude = 0;

            PolylineOptions lineOptions = new PolylineOptions();

            lineOptions.Clickable(true);

            latitude  = double.Parse(latlng[0]);
            longitude = double.Parse(latlng[1]);
            lineOptions.Add(new LatLng(latitude, longitude));

            //lineOptions.InvokeColor(colorList[currentColor]);

            foreach (string coord in pathCoords)
            {
                try
                {
                    latlng = coord.Split(',');

                    if (latlng.Length > 0)
                    {
                        latitude  = double.Parse(latlng[0]);
                        longitude = double.Parse(latlng[1]);

                        lineOptions.Add(new LatLng(latitude, longitude));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error translating path values: LoadTrailPath");
                    Console.WriteLine(ex.ToString());
                }
            }

            latlng    = end.Split(',');
            latitude  = double.Parse(latlng[0]);
            longitude = double.Parse(latlng[1]);
            lineOptions.Add(new LatLng(latitude, longitude));

            if (pathCoords.Length > 0)
            {
                PathList.Add(_map.AddPolyline(lineOptions));
            }
        }
Ejemplo n.º 7
0
        private void OnMarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
        {
            if (currentLocation == null)
            {
                Console.Write("Location could not be determined");
                return;
            }

            LatLng startLocation = new LatLng(currentLocation.Latitude,
                                              currentLocation.Longitude);

            Marker tarketMarker   = e.Marker;
            LatLng targetLocation = tarketMarker.Position;

            String url = "https://maps.googleapis.com/maps/api/directions/json"
                         + "?origin=" + startLocation.Latitude + "," + startLocation.Longitude
                         + "&destination=" + targetLocation.Latitude + "," + targetLocation.Longitude
                         + "&sensor=false&units=metric&mode=walking"
                         + "&key=" + Resources.GetString(Resource.String.maps_api_key);

            // Get json data from the internet
            WebRequest  request  = WebRequest.Create(url);
            WebResponse response = request.GetResponseAsync().Result;
            Stream      stream   = response.GetResponseStream();

            // Read json string from stream
            string JsonResponse = new StreamReader(stream).ReadToEnd();

            PolyRoute PolyRoute = JsonConvert
                                  .DeserializeObject <PolyRoute>(JsonResponse);

            Step[] Steps = PolyRoute.routes[0].legs[0].steps;


            var RouteOptions = new PolylineOptions();

            RouteOptions.InvokeColor(Android.Graphics.Color.Blue);

            RouteOptions.Add(new LatLng(Steps[0].start_location.lat, Steps[0].start_location.lng));
            foreach (Step Step in Steps)
            {
                RouteOptions.Add(new LatLng(Step.end_location.lat, Step.end_location.lng));
            }
            if (polyline != null)
            {
                polyline.Remove();
            }
            polyline = NativeMap.AddPolyline(RouteOptions);
        }
Ejemplo n.º 8
0
        private void AddPolylines()
        {
            // 绘制一个虚线三角形
            var polylineOptions = new PolylineOptions();

            //添加坐标点,按照点的顺序依次连接
            // 如果点已经在列表中,您可以调用 PolylineOptions.addAll() 方法
            polylineOptions.Add(new LatLng(30.779879, 104.064855));
            polylineOptions.Add(new LatLng(39.936713, 116.386475));
            polylineOptions.Add(new LatLng(39.02, 120.51));
            //InvokeWidth :设置宽度;
            //SetDottedLine:设置虚线;
            polylineOptions.InvokeWidth(10).SetDottedLine(true).Geodesic(true).InvokeColor(Color.Argb(255, 1, 1, 1));
            aMap.AddPolyline(polylineOptions);
        }
 private void FormsMap_AddedPosition(object sender, NewPositionEventArgs e)
 {
     if (_isMapReady == true && routeCoordinates.Count() > 0 && e.ShowPath == true && routeCoordinates.Last() is Position lastPos)
     {
         if (NativeMap != null)
         {
             var polylineOptions = new PolylineOptions();
             polylineOptions.InvokeColor(_mapLineColor);
             polylineOptions.Add(new LatLng(lastPos.Latitude, lastPos.Longitude));
             polylineOptions.Add(new LatLng(e.Position.Latitude, e.Position.Longitude));
             NativeMap.AddPolyline(polylineOptions);
         }
     }
     routeCoordinates.Add(e.Position);
 }
Ejemplo n.º 10
0
        void FnSetDirectionQuery(string strJSONDirectionResponse)
        {
            var objRoutes = JsonConvert.DeserializeObject <GoogleDirectionClass> (strJSONDirectionResponse);

            //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++] = loc;                     //new LatLng ( loc.Latitude , loc.Longitude );
                }

                var polylineoption = new PolylineOptions();
                polylineoption.InvokeColor(Android.Graphics.Color.Green);
                polylineoption.Geodesic(true);
                polylineoption.Add(latLngPoints);
                RunOnUiThread(() =>
                              eMap.AddPolyline(polylineoption));
            }
        }
Ejemplo n.º 11
0
        void DibujarRuta()
        {
            try
            {
                var options = new PolylineOptions();

                var colorInt = Colores.Accent;

                options.InvokeColor(colorInt);
                options.InvokeWidth(5);
                options.Visible(true);

                foreach (var posicion in _posiciones.OrderBy(p => p.Fecha))
                {
                    var coordenada = posicion.Coordenada;

                    options.Add(new LatLng(coordenada.Latitud, coordenada.Longitud));
                }

                _mapa.AddPolyline(options);
            }
            catch (Exception ex)
            {
                AlertMessage.Show(Activity, $"Ha ocurrido un error: {ex.Message}", ToastLength.Long);
            }
        }
Ejemplo n.º 12
0
        private void addConePolyline(double angle, GeodeticCalculator geoCalculator, CustomMap customMap, LatLng userPos, double distTarget)
        {
            var polylineOptions = new PolylineOptions();

            polylineOptions.Clickable(true);
            polylineOptions.InvokeJointType(JointType.Round);
            polylineOptions.InvokeWidth(10f);
            polylineOptions.InvokeColor(0x664444FF);

            polylineOptions.Add(userPos);
            LatLng conePoint = movePoint(angle, customMap.UserPin.Position, customMap.TargetPin.Position);

            Console.WriteLine("conePoint dist = " + CustomMap.DistanceTo(customMap.UserPin.Position.Latitude, customMap.UserPin.Position.Longitude, conePoint.Latitude, conePoint.Longitude, "M"));
            polylineOptions.Add(conePoint);
            coneLines.Add(map.AddPolyline(polylineOptions));
        }
Ejemplo n.º 13
0
        private void DrawTracksButton_Click(object sender, EventArgs e)
        {
            var points = journeyPointRespository.GetTrackPointsForJourney(SelectedJourneyId);

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            PolylineOptions      line    = new PolylineOptions().InvokeColor(Color.Purple);


            if (points.Count() > 0)
            {
                MarkerOptions moStart = new MarkerOptions();
                moStart.SetPosition(new LatLng(points.ElementAt(0).Lat, points.ElementAt(0).Lon));
                moStart.SetIcon((BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen)));

                foreach (var v in points)
                {
                    LatLng l = new LatLng(v.Lat, v.Lon);
                    builder.Include(l);
                    line.Add(l);
                }

                MarkerOptions moEnd = new MarkerOptions();
                moEnd.SetPosition(new LatLng(points.ElementAt(points.Count() - 1).Lat, points.ElementAt(points.Count() - 1).Lon));
                moEnd.SetIcon((BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed)));

                _map.AddPolyline(line);
                _map.AddMarker(moStart);
                _map.AddMarker(moEnd);
                _map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), 80));
            }
        }
Ejemplo n.º 14
0
        protected override void OnMapReady(GoogleMap map)
        {
            base.OnMapReady(map);
            _map = map;
            _map.UiSettings.MyLocationButtonEnabled = false;
            _map.UiSettings.ZoomControlsEnabled     = false;
            _map.UiSettings.ZoomGesturesEnabled     = true;
            _map.UiSettings.RotateGesturesEnabled   = true;

            if (_map != null)
            {
                _map.MapClick += googleMapClick;
            }
            if (NativeMap != null)
            {
                var polylineOptions = new PolylineOptions();
                polylineOptions.InvokeColor(0x66FF0000);
                foreach (var position in _polylinePosicoes)
                {
                    polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                }
                _polyline = NativeMap.AddPolyline(polylineOptions);
            }
            if (_mapaForm != null)
            {
                if (!_inicializouMapa)
                {
                    _mapaForm.inicializarMapa();
                    _inicializouMapa = true;
                }
            }
        }
Ejemplo n.º 15
0
        protected override void OnMapReady(GoogleMap map)
        {
            base.OnMapReady(map);

            var polylineOptions = new PolylineOptions();

            polylineOptions.InvokeColor(0x702418ff);

            foreach (var position in routeCoordinates)
            {
                polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
            }

            NativeMap.AddPolyline(polylineOptions);

            foreach (Bus bus in BusList.busList)
            {
                if (bus.route == "blue")
                {
                    CircleOptions circleOptions = new CircleOptions();
                    circleOptions.InvokeCenter(new LatLng(bus.lat, bus.lng));
                    circleOptions.InvokeRadius(30);
                    circleOptions.InvokeFillColor(0X700000ff);
                    circleOptions.InvokeStrokeColor(0X70FFFFFF);
                    circleOptions.InvokeStrokeWidth(5);

                    NativeMap.AddCircle(circleOptions);
                }
            }
        }
Ejemplo n.º 16
0
        private void MostrarVagasNoMapa(JObject ponto, JArray lista)
        {
            if (lista != null)
            {
                foreach (var vaga in lista)
                {
                    var           latitude  = (vaga["Localizacao"])["Latitude"].Value <double>();
                    var           longitude = (vaga["Localizacao"])["Longitude"].Value <double>();
                    var           altitude  = (vaga["Localizacao"])["Altitude"].Value <double>();
                    LatLng        latlng    = new LatLng(Convert.ToDouble(latitude), Convert.ToDouble(longitude));
                    MarkerOptions options   = new MarkerOptions().SetPosition(latlng).SetTitle(vaga["Numero"].Value <long>().ToString());
                    GMap.AddMarker(options);


                    var             _latitude  = (ponto["Localizacao"])["Latitude"].Value <double>();
                    var             _longitude = (ponto["Localizacao"])["Longitude"].Value <double>();
                    var             _altitude  = (ponto["Localizacao"])["Altitude"].Value <double>();
                    PolylineOptions opt        = new PolylineOptions();
                    opt = opt.Add(new LatLng(latitude, longitude), new LatLng(_latitude, _longitude));
                    opt = opt.InvokeWidth(5);
                    opt = opt.InvokeColor(Color.Blue);

                    Polyline line = GMap.AddPolyline(opt);
                }
            }
        }
Ejemplo n.º 17
0
        void FnSetDirectionQuery(string strJSONDirectionResponse)
        {
            //var txtResult = FindViewById<TextView>(Resource.Id.textResult);

            var objRoutes = JsonConvert.DeserializeObject <GoogleDirectionClass>(strJSONDirectionResponse);

            //objRoutes.routes.Count  --may be more then one
            //if (objRoutes.routes.Count != 0)
            if (true)
            {
                //string encodedPoints = objRoutes.routes[0].overview_polyline.points;
                //List<LatLng> lstDecodedPoints = DecodePolyline(encodedPoints);
                List <LatLng> lstDecodedPoints = DecodePolyline("yf}`Bk|osS}E\\kBFo@UEEOCMFCNDLDB@?FjBNxAH~@z@xMh@~Hl@|GNtCHbAGXUr@wDnHcDxFY\\_@\\I@OBUNINkBNwBXgCTiHf@k@D}BXuAd@yAp@k@d@_@`@Uf@CAEAQAQDONCLAR@BKLU`@OPg@^eAn@SH_Cn@q@Na@PCCEEOCOBKNAH?BYLuE`ByD|AcJ|EsBx@_JxCoBt@o@n@@^@tBFzEP|@D~BHxEExGKhFIpDE~FSrIEvBC`E@tCT|GlCAXbJ`Bi@bAo@NGKi@?E?CDE@G");

                var polylineOptions = new PolylineOptions();
                polylineOptions = new PolylineOptions();
                polylineOptions.InvokeColor(global::Android.Graphics.Color.Red);
                polylineOptions.InvokeWidth(4);

                foreach (LatLng line in lstDecodedPoints)
                {
                    polylineOptions.Add(line);
                }

                map.AddPolyline(polylineOptions);
            }
        }
Ejemplo n.º 18
0
        private void ShowTheWay()
        {
            PolylineOptions polylineOptions = new PolylineOptions();
            LatLngBounds    bounds;

            LatLng[] points = location.getPath(sourceMarkerOptions.Position, destinationMarkerOptions.Position, out bounds);
            polylineOptions.Add(points);
            googleMap.AddPolyline(polylineOptions);

            var filteredSites = location.allSites.Where(x => bounds.Contains(x.Item1));


            googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 60), 2000, null);


            inputManager.HideSoftInputFromWindow(this.CurrentFocus.WindowToken, HideSoftInputFlags.None);

            foreach (var site in filteredSites)
            {
                var markerOp = new MarkerOptions();
                markerOp.SetPosition(site.Item1);
                markerOp.SetTitle(site.Item2);
                googleMap.AddMarker(markerOp);
            }
        }
Ejemplo n.º 19
0
        public void DrawRouteToPlace(Route route, Place place)
        {
            if (MyLocation == null)
            {
                return;
            }

            map.Clear();

            string snippet = route.legs[0].distance.text +
                             ", " + route.legs[0].duration.text;

            var marker = new MarkerOptions();

            marker.SetTitle(place.name);
            marker.SetSnippet(snippet);
            marker.SetPosition(new LatLng(place.geometry.location.lat, place.geometry.location.lng));
            map.AddMarker(marker);

            var polyline = new PolylineOptions();

            polyline.InvokeColor(ContextCompat.GetColor(Activity.ApplicationContext, Resource.Color.route_polyline));
            var points = RouteHelper.GetPointsFromRoute(route);

            foreach (var point in points)
            {
                polyline.Add(new LatLng(point.lat, point.lng));
            }

            map.AddPolyline(polyline);

            UpdateCameraPosition(new LatLng(MyLocation.lat, MyLocation.lng));
        }
Ejemplo n.º 20
0
 private void resetarPolyline(IList <Position> novaRota)
 {
     if (_polyline != null)
     {
         _polyline.Remove();
         _polyline.Dispose();
         _polyline = null;
     }
     if (NativeMap != null)
     {
         var polylineOptions = new PolylineOptions();
         polylineOptions.InvokeColor(0x66FF0000);
         while (polylineOptions.Points != null && polylineOptions.Points.Count > 0)
         {
             polylineOptions.Points.RemoveAt(0);
         }
         if (novaRota != null)
         {
             foreach (var position in novaRota)
             {
                 polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
             }
             _polyline = NativeMap.AddPolyline(polylineOptions);
         }
     }
 }
Ejemplo n.º 21
0
        private void _routeCoordinates_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            //highlighting route
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                var latestPosition = _routeCoordinates[_routeCoordinates.Count - 1];
                if (_routeCoordinates.Count > 1)
                {
                    var polylineOptions = new PolylineOptions();
                    polylineOptions.InvokeColor(0x66FF0000);
                    foreach (var position in _routeCoordinates)
                    {
                        polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                    }

                    if (NativeMap == null)
                    {
                        Log.Debug(TAG, "null Native Map");
                    }
                    else
                    {
                        Log.Debug(TAG, "Native Map is not null");
                        Polyline polyline = NativeMap.AddPolyline(polylineOptions);
                    }
                }
            }
            else
            {
                Log.Debug(TAG, "not ADD action");
            }
        }
Ejemplo n.º 22
0
        public async void FindRouteAsync(string source, string destrination) // radi sa primerom https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&mode=transit&key=AIzaSyDY8RF7Oa9h5IeD7DX6l_GtGPnjT6J7k4U
        {
            client = new HttpClient();
            // string default_for_every_query = "https://maps.googleapis.com/maps/api/directions/json?";

            HttpResponseMessage response = await client.GetAsync("https://maps.googleapis.com/maps/api/directions/json?origin=" + source + "&destination=" + destrination + "&mode=transit&key=AIzaSyDY8RF7Oa9h5IeD7DX6l_GtGPnjT6J7k4U");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                HttpContent content = response.Content;
                var         json    = await content.ReadAsStringAsync();

                Console.WriteLine(json.ToString());

                JSONObject    jsonresoult       = new JSONObject(json);
                JSONArray     routesArray       = jsonresoult.GetJSONArray("routes");
                JSONObject    routes            = routesArray.GetJSONObject(0);
                JSONObject    overviewPolylines = routes.GetJSONObject("overview_polyline");
                String        encodedString     = overviewPolylines.GetString("points");
                List <LatLng> list = decodePoly(encodedString);

                PolylineOptions po = new PolylineOptions();
                //treba i < list.Count zasto puca sa tim?

                for (int i = 0; i < list.Count; i++)
                {
                    po.Add(list[i]).InvokeWidth(10).InvokeColor(0x66FF0000);//red color
                }

                gmap.AddPolyline(po);
            }
        }
Ejemplo n.º 23
0
        public void OnMapReady(GoogleMap googleMap)
        {
            map = googleMap;

            var polylineOptions = new PolylineOptions();

            polylineOptions.InvokeColor(0x66FF0000);

            foreach (var position in calculatedRoute)
            {
                polylineOptions.Add(new LatLng(position.Lat, position.Lon));
            }
            map.AddPolyline(polylineOptions);


            polylineOptions = new PolylineOptions();
            polylineOptions.InvokeColor(customerapp.Droid.Resource.Color.green);
            polylineOptions.InvokeWidth(10);

            foreach (var position in flownRoute)
            {
                polylineOptions.Add(new LatLng(position.Lat, position.Lon));
            }
            map.AddPolyline(polylineOptions);
        }
Ejemplo n.º 24
0
        void AddPolylines(IList polylines)
        {
            var map = NativeMap;

            if (map == null)
            {
                return;
            }

            if (_polylines == null)
            {
                _polylines = new List <APolyline>();
            }

            _polylines.AddRange(polylines.Cast <Polyline>().Select(line =>
            {
                var polyline = (Polyline)line;
                var opts     = new PolylineOptions();

                foreach (var p in polyline.Positions)
                {
                    opts.Add(new LatLng(p.Latitude, p.Longitude));
                }

                opts.InvokeWidth(polyline.StrokeWidth * _scaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps)
                opts.InvokeColor(polyline.StrokeColor.ToAndroid());
                opts.Clickable(polyline.IsClickable);

                var nativePolyline = map.AddPolyline(opts);

                // associate pin with marker for later lookup in event handlers
                polyline.Id = nativePolyline;
                return(nativePolyline);
            }));
        }
Ejemplo n.º 25
0
        private void ColocarNovoPontoMapa(LatLng latlngOrigem, LatLng latlngDest, JObject estacionamento)
        {
            MarkerOptions options = new MarkerOptions().SetPosition(latlngOrigem).SetTitle("").SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.dot));

            Marker ponto = GMap.AddMarker(options);

            Marcador marcador = new Marcador(estacionamento, ponto);

            if (latlngDest != null)
            {
                var _latitude  = latlngDest.Latitude;
                var _longitude = latlngDest.Longitude;
                //var _altitude = (ponto["Localizacao"])["Altitude"].Value<double>();
                PolylineOptions opt = new PolylineOptions();
                opt = opt.Add(latlngOrigem, new LatLng(_latitude, _longitude));
                opt = opt.InvokeWidth(5);
                opt = opt.InvokeColor(Color.Red);

                Polyline line = GMap.AddPolyline(opt);
                marcador.Linhas.Add(line);
            }
            if (UltimoPontoInteracao != null)
            {
                marcador.Conexoes.Add(long.Parse(UltimoPontoInteracao.Title));
            }
            marcador             = SalvarPontoInserido(marcador);
            UltimoPontoInteracao = marcador.Marker;
            this.MarcadoresColocados.Add(marcador);
        }
Ejemplo n.º 26
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == "RouteCoordinates" || e.PropertyName == "VisibleRegion")
            {
                CustomMap cMap = (CustomMap)this.Element;
                if (cMap.RouteCoordinates != null)
                {
                    var polylineOptions = new PolylineOptions();
                    polylineOptions.InvokeColor(0x66FF0000);

                    // limpa percurso
                    ((Activity)Forms.Context).RunOnUiThread(() => map.Clear());

                    // adiciona posições do percurso já percorrido
                    foreach (var position in cMap.RouteCoordinates)
                    {
                        polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                    }

                    // desenha percurso no mapa
                    ((Activity)Forms.Context).RunOnUiThread(() => map.AddPolyline(polylineOptions));
                }
            }
        }
Ejemplo n.º 27
0
        void OnInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
        {
            var customPin = GetCustomPin(e.Marker);

            if (customPin == null)
            {
                throw new Exception("Custom pin not found");
            }

            //draw route
            _finalPolyline = null;
            if (customPin.RouteCoordinates.Any())
            {
                var polylineOptions = new PolylineOptions();
                polylineOptions.InvokeColor(0x66FF0000);
                foreach (var coordinate in customPin.RouteCoordinates)
                {
                    polylineOptions.Add(new LatLng(coordinate.Latitude, coordinate.Longitude));
                }
                _finalPolyline = base.NativeMap.AddPolyline(polylineOptions);
            }

            if (!string.IsNullOrWhiteSpace(customPin.Url))
            {
                var url    = Android.Net.Uri.Parse(customPin.Url);
                var intent = new Intent(Intent.ActionView, url);
                intent.AddFlags(ActivityFlags.NewTask);
                Android.App.Application.Context.StartActivity(intent);
            }
        }
Ejemplo n.º 28
0
        private void ShowRouteOverview()
        {
            NativeMap.Clear();

            PolylineOptions selectedRoutePolyline = new PolylineOptions();

            selectedRoutePolyline.InvokeColor(Resource.Color.colorPrimaryDark);
            selectedRoutePolyline.InvokeWidth(20f);

            LatLng[] allRoutePoints = _xamap.SelectedRoute.Legs
                                      .SelectMany(leg => leg.Points)
                                      .Select(point => new LatLng(point.Latitude, point.Longitude))
                                      .ToArray();

            selectedRoutePolyline.Add(allRoutePoints);
            NativeMap.AddPolyline(selectedRoutePolyline);

            LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
            LatLngBounds         routeBounds   = allRoutePoints
                                                 .Aggregate(boundsBuilder, (builder, latLng) => builder.Include(latLng))
                                                 .Build();

            CameraUpdate routeOverviewMapUpdate = CameraUpdateFactory.NewLatLngBounds(routeBounds, 50);

            NativeMap.AnimateCamera(routeOverviewMapUpdate);
        }
Ejemplo n.º 29
0
        private void UpdateRouteCoordinates()
        {
            var customMap = Element as CustomMap;

            RemoveRouteCoordinates();

            foreach (var routeCoordinates in customMap.RouteCoordinates)
            {
                foreach (var positionEstimate in routeCoordinates.PositionEstimates)
                {
                    if (routeCoordinates.Submitter == null)
                    {
                        return;
                    }

                    var trackColor      = GetColor(routeCoordinates.Color);
                    var polylineOptions = new PolylineOptions();

                    polylineOptions.InvokeColor(trackColor);

                    foreach (var actualPosition in positionEstimate.ActualPositions)
                    {
                        polylineOptions.Add(new LatLng(actualPosition.Latitude, actualPosition.Longitude));
                    }

                    _polyline = _googleMap.AddPolyline(polylineOptions);
                    _polylines.Add(_polyline);
                }
            }
        }
Ejemplo n.º 30
0
        protected override NativePolyline CreateNativeItem(Polyline outerItem)
        {
            var opts = new PolylineOptions();

            foreach (var p in outerItem.Positions)
            {
                opts.Add(new LatLng(p.Latitude, p.Longitude));
            }

            opts.InvokeWidth(outerItem.StrokeWidth * this.ScaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps)
            opts.InvokeColor(outerItem.StrokeColor.ToAndroid());
            opts.Clickable(outerItem.IsClickable);
            opts.InvokeZIndex(outerItem.ZIndex);

            var nativePolyline = NativeMap.AddPolyline(opts);

            // associate pin with marker for later lookup in event handlers
            outerItem.NativeObject = nativePolyline;
            outerItem.SetOnPositionsChanged((polyline, e) =>
            {
                var native    = polyline.NativeObject as NativePolyline;
                native.Points = polyline.Positions.ToLatLngs();
            });

            return(nativePolyline);
        }