예제 #1
0
        public MapRoute(GoogleMap map, List<Station> stations)
        {
            _map = map;
            _mapRoutes = new List<Polyline>();
            _mapStations = new List<Marker>();

            // Choose color;
            Color color = Color.DodgerBlue;

            // Create polyline.
            var polyline = new PolylineOptions();
            polyline.InvokeWidth(4f);
            polyline.InvokeColor(color);

            for (var i = 0; i < stations.Count; i++)
            {
                // Add points to polyline.
                var station = stations[i];
                if (station != null && station.latitude != 0f && station.longitude != 0f)
                {
                    var latlng = new Android.Gms.Maps.Model.LatLng(station.latitude, station.longitude);
                    polyline.Add(latlng);
                    // Create marker.
                    var marker = new MarkerOptions();
                    marker.SetPosition(latlng);
                    marker.SetTitle((i + 1) + ". " + station.postName);
                    marker.Draggable(false);
                    marker.SetSnippet("ul. " + station.street);
                    _mapStations.Add(_map.AddMarker(marker));
                }
            }

            // Add polyline to map.
            _mapRoutes.Add(_map.AddPolyline(polyline));
        }
		public void OnMapReady (GoogleMap googleMap)
		{
			map = googleMap;

			var polylineOptions = new PolylineOptions ();
			polylineOptions.InvokeColor (0x66FF0000);

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

			map.AddPolyline (polylineOptions);
		}
			protected override void DrawPolyline (List<GeoLoc> polyLine)
			{
				if (polyLine == null || polyLine.Count == 0)
					return;

				var map = _mapFragment.Map;
				// draw routes
				PolylineOptions options = new PolylineOptions ().Geodesic (true);
				if(polyLine == _highlighedPoint.Polyline){
					options.InvokeWidth (7); 
					options.InvokeColor (System.Drawing.Color.Blue.ToArgb());
				} else {
					options.InvokeWidth (3); 
					options.InvokeColor (System.Drawing.Color.LightBlue.ToArgb());
				}
				polyLine.ForEach (x => options.Add (Utils.GetLatLng(x)));
				_routeLines.Add(map.AddPolyline(options));
			}
예제 #4
0
        public static PolylineAdv Add(GoogleMap map, PolylineOptions op)
        {
            var polyline = new PolylineAdv(map, op);
            var idxStart = 0;
            while (idxStart < op.Points.Count)
            {
                using (var options = CloneOptions(op))
                {
                    for (var i = idxStart; i < Math.Min(idxStart + PolylineSegmentLength + 1, op.Points.Count); i++)
                    {
                        options.Add(op.Points[i]);
                    }
                    polyline._polylines.Add(map.AddPolyline(options));
                }

                idxStart += PolylineSegmentLength;
            }

            return polyline;
        }
        /// <summary>
        /// Adds a route to the map
        /// </summary>
        /// <param name="line">The route to add</param>
        private void AddLine(TKPolyline line)
        {
            line.PropertyChanged += OnLinePropertyChanged;
            
            var polylineOptions = new PolylineOptions();
            if (line.Color != Color.Default)
            {
                polylineOptions.InvokeColor(line.Color.ToAndroid().ToArgb());
            }
            if (line.LineWidth > 0)
            {
                polylineOptions.InvokeWidth(line.LineWidth);
            }

            if (line.LineCoordinates != null)
            {
                polylineOptions.Add(line.LineCoordinates.Select(i => i.ToLatLng()).ToArray());
            }

            this._polylines.Add(line, this._googleMap.AddPolyline(polylineOptions));
        }
예제 #6
0
		private void SetupMapIfNeeded()
		{
			if (_map == null)
			{
				_map = _mapFragment.Map;
				if (_map != null)
				{
					var centerPoint = new LatLng (Station.TroncalRouteCenter.Y, Station.TroncalRouteCenter.X);
					Activity.RunOnUiThread (delegate{
						_map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(centerPoint,15.0f));
						_map.MyLocationEnabled = true;
					});
					stations = stationRepository.Stations;
					Activity.RunOnUiThread (delegate{
						foreach(var station in stations){
							var location = new LatLng(station.Latitude, station.Longitude);
							var stationImageId = Resources.GetIdentifier( station.ImageFilename().ToLower(), "drawable", Activity.PackageName);
							var originalStationBitmap = BitmapFactory.DecodeResource(Resources, stationImageId);
							var scale = Resources.DisplayMetrics.Density;
							var pixels = 35;
							var stationBitmap = Bitmap.CreateScaledBitmap(originalStationBitmap, (int) (pixels * scale + 0.5f), (int) (pixels * scale + 0.5f), false);
							MarkerOptions markerOptions = new MarkerOptions()
								.SetPosition(location)
								.InvokeIcon(BitmapDescriptorFactory.FromBitmap(stationBitmap))
								.SetTitle(station.Name);
							_map.AddMarker(markerOptions);
						}
						var polylineOptions = new PolylineOptions();
						polylineOptions.InvokeWidth(5.0f);
						polylineOptions.InvokeColor(Color.Black);
						foreach(var point in Station.TroncalRoutePath){
							polylineOptions.Add(new LatLng(point.Y, point.X));
						}
						_map.AddPolyline(polylineOptions);
					});
				}
			}
		}
예제 #7
0
		public async Task<Polyline> DrawRoute (string origin, string destination)
		{
			//string origin="45.81444,15.97798";
			//string destination="45.80109,15.97082";
			//Polyline ruta;
			PolylineOptions linija = new PolylineOptions();
			linija.InvokeColor(-16776961);
			string url = "https://maps.googleapis.com/maps/api/directions/json?origin="+origin+"&destination="+destination+"&mode=walking&region=hr&key=AIzaSyAi5T6O9DsVUJ3HMN4xDpfGf9qupGjY7xQ";
			Console.WriteLine (url);
			var json = await getJson (url);
			string jsonString = json.ToString ();
			Regex points = new Regex ("\"polyline\": {\"points\": \"(.*?)},");
			Match polypoints = points.Match (jsonString);
			while (polypoints.Success) {
				string finalni = polypoints.Groups [0].ToString ();
				finalni=finalni.Substring(24, finalni.Length-24);
				finalni=finalni.Remove(finalni.Length-3);
				finalni = finalni.Replace("\\\\", "\\");
				List<LatLng> privremeni = DecodePolylinePoints(finalni);
				for (int i = 0; i <privremeni.Count; i++)
				{
					linija.Add (new LatLng (privremeni[i].Latitude, privremeni[i].Longitude));
				}
				polypoints = polypoints.NextMatch ();
			}

			try{
				ruta.Remove();
			}
			catch (Exception){

			}
			return ruta=mMap.AddPolyline(linija);
		}
예제 #8
0
        public Task<DirectionHolder> GetDirectionsAsync()
        {
            if (directionsTCS != null)
            {
                if (!directionsTCS.Task.IsCompleted)
                    directionsTCS.TrySetCanceled();
                directionsTCS = new TaskCompletionSource<DirectionHolder>();
            }

            if (_lastUserLocation != null && currentMarkerPosition != null)
            {
                Task.Run(async () =>
                {
                    try
                    {
                        // Getting URL to the Google Directions API
                        var url = GetDirectionsUrl(_lastUserLocation, currentMarkerPosition);
                        using (var client = new HttpClient(new NativeMessageHandler()))
                        {
                            var response = await client.GetAsync(url).ConfigureAwait(false);
                            var responseBodyAsText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                            var directions = JsonConvert.DeserializeObject<DirectionsModel>(responseBodyAsText);
                            PolylineOptions lineOptions = new PolylineOptions();
                            lineOptions = lineOptions.InvokeColor(Resources.GetColor(Resource.Color.accent).ToArgb());
                            lineOptions = lineOptions.InvokeWidth(15);

                            if (directions.routes.FirstOrDefault() != null)
                            {
                                var duration = directions.routes.FirstOrDefault().legs.FirstOrDefault().duration;
                                var distance = directions.routes.FirstOrDefault().legs.FirstOrDefault().distance;
                                var points = MapHelper.DecodePolyline(directions.routes.FirstOrDefault().overview_polyline.points).AsEnumerable();
                                foreach (var point in points)
                                {
                                    lineOptions.Add(point);
                                }
                                directionsTCS.SetResult(new DirectionHolder
                                {
                                    Distance = distance.text,
                                    Duration = duration.text,
                                    Polylines = lineOptions
                                });

                            }
                        }
                    }
                    catch
                    {
                    }
                });

            }
            return directionsTCS.Task;
        }
예제 #9
0
 private PolylineOptions CreatePolylineOptions(MapPolyline polyline)
 {
     var op = new PolylineOptions();
     op.InvokeColor(polyline.Color.ToAndroid().ToArgb());
     op.InvokeWidth((float)polyline.Width);
     op.InvokeZIndex(polyline.ZIndex);
     return op;
 }
예제 #10
0
        void DrawRunTrack(bool mapShouldFollow)
        {
            if (mRunLocations.Count < 1)
                return;
            // Set up overlay for the map with the current run's locations
            // Create a polyline with all of the points
            PolylineOptions line = new PolylineOptions();
            // Create a LatLngBounds so you can zoom to fit
            LatLngBounds.Builder latLngBuilder = new LatLngBounds.Builder();
            // Add the locations of the current run
            foreach (RunLocation loc in mRunLocations) {
                LatLng latLng = new LatLng(loc.Latitude, loc.Longitude);
                line.Add(latLng);
                latLngBuilder.Include(latLng);
            }
            // Add the polyline to the map
            mGoogleMap.AddPolyline(line);

            // Add markers
            LatLng startLatLng = new LatLng(mRunLocations[0].Latitude, mRunLocations[0].Longitude);
            MarkerOptions startMarkerOptions = new MarkerOptions();
            startMarkerOptions.SetPosition(startLatLng);
            startMarkerOptions.SetTitle(Activity.GetString(Resource.String.run_start));
            startMarkerOptions.SetSnippet(Activity.GetString(Resource.String.run_started_at_format, new Java.Lang.Object[]{new Java.Lang.String(mRunLocations[0].Time.ToLocalTime().ToLongTimeString())}));
            mGoogleMap.AddMarker(startMarkerOptions);

            var activeRun = mRunManager.GetActiveRun();

            if (activeRun == null || (activeRun != null && CurrentRun.Id != activeRun.Id)) {
                LatLng stopLatLng = new LatLng(mRunLocations[mRunLocations.Count-1].Latitude, mRunLocations[mRunLocations.Count-1].Longitude);
                MarkerOptions stopMarkerOptions = new MarkerOptions();
                stopMarkerOptions.SetPosition(stopLatLng);
                stopMarkerOptions.SetTitle(Activity.GetString(Resource.String.run_finish));
                stopMarkerOptions.SetSnippet(Activity.GetString(Resource.String.run_finished_at_format, new Java.Lang.Object[]{new Java.Lang.String(mRunLocations[mRunLocations.Count-1].Time.ToLocalTime().ToLongTimeString())}));
                mGoogleMap.AddMarker(stopMarkerOptions);
            }

            // Make the map zoom to show the track, with some padding
            // Use the size of the map linear layout in pixels as a bounding box
            LatLngBounds latLngBounds = latLngBuilder.Build();
            // Construct a movement instruction for the map
            CameraUpdate movement = CameraUpdateFactory.NewLatLngBounds(latLngBounds, mMapWidth, mMapHeight, 50);
            if (mMapShouldFollow) {
                try {
                    mGoogleMap.MoveCamera(movement);
                    mMapShouldFollow = mapShouldFollow;
                }
                catch (Exception ex) {
                    Console.WriteLine("[{0}] No Layout yet {1}", TAG, ex.Message);
                }
            }
        }
예제 #11
0
		/// <summary>
		/// Draw line from active location to active object, if it is a zone.
		/// </summary>
		void UpdateDistanceLine ()
		{
			if (activeObject != null && activeObject is Zone) {
				if (activeObject is Zone && ((Zone)activeObject).State != PlayerZoneState.Inside) {
					if (distanceLine == null) {
						// Draw line
						PolylineOptions po = new PolylineOptions();
						po.Points.Add (new LatLng (Main.GPS.Location.Latitude, Main.GPS.Location.Longitude));
						po.Points.Add (new LatLng (((Zone)activeObject).ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude)); //.ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude));
						po.InvokeColor(Color.Cyan);
						po.InvokeWidth(4);
						po.InvokeZIndex(2);
						distanceLine = _map.AddPolyline(po);
					} else {
						// Set new line points
						List<LatLng> points = new List<LatLng>(2);
						points.Add (new LatLng (Main.GPS.Location.Latitude, Main.GPS.Location.Longitude));
						points.Add (new LatLng (((Zone)activeObject).ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude)); //.ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude));
						distanceLine.Points = points;
					}
				} else {
					// Delete line
					if (distanceLine != null) {
						distanceLine.Remove ();
						distanceLine = null;
					}
				}
			} else {
				// Delete line
				if (distanceLine != null) {
					distanceLine.Remove ();
					distanceLine = null;
				}
			}
		}
예제 #12
0
 private PolylineAdv(GoogleMap map, PolylineOptions options)
 {
     _map = map;
     _options = CloneOptions(options);
 }
예제 #13
0
 private static PolylineOptions CloneOptions(PolylineOptions op)
 {
     var options = new PolylineOptions();
     options.InvokeColor(op.Color);
     options.InvokeWidth(op.Width);
     options.InvokeZIndex(op.ZIndex);
     return options;
 }
        //void MapOnCircleClick(object sender, GoogleMap.CircleClickEventArgs eventArgs)
        //{
        //    // clicked polygon
        //    var clickedCircle = eventArgs.Circle;

        //    // lookup pin
        //    Circle targetCircle = null;
        //    for (var i = 0; i < Map.Circles.Count; i++)
        //    {
        //        var circle = Map.Circles[i];
        //        if ((string)circle.Id != clickedCircle.Id)
        //            continue;

        //        targetCircle = circle;
        //        break;
        //    }

        //    // only consider event handled if a handler is present. 
        //    // Else allow default behavior of displaying an info window.
        //    targetCircle?.SendTap();
        //}

        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;
            }));
        }
 private void getDirection()
 {
     DirectionController n = new DirectionController (this, myLatitude, myLongitude, drugLatitude, drugLongitude, "AIzaSyDq4KITG5eySbUdYn-FqHamOdrs6BKoVKU");
     listLocation = n.listLocation;
     LatLng mCamera = null;//move camera
     PolylineOptions polyOptions = new PolylineOptions ();
     foreach (myLocation item in listLocation) {
         LatLng addLat = new LatLng (item.latitude, item.longitude);
         if (item == listLocation [((listLocation.Count) / 2)]) {
             mCamera = new LatLng (item.latitude, item.longitude);
             moveCamera (mCamera, 0);
         }
         polyOptions.Add (addLat);
     }
     Polyline polyLine = googleMap.AddPolyline (polyOptions);
     polyLine.Color = Android.Graphics.Color.Blue;
     polyLine.Width = 5;
 }
        /// <summary>
        /// Calculates and adds the route to the map
        /// </summary>
        /// <param name="route">The route to add</param>
        private async void AddRoute(TKRoute route)
        {
            route.PropertyChanged += OnRoutePropertyChanged;

            GmsDirectionResult routeData = null;
            try
            {
                routeData = await GmsDirection.Instance.CalculateRoute(route.Source, route.Destination, route.TravelMode.ToGmsTravelMode());
                
                if (routeData == null || routeData.Routes == null) return;

                var r = routeData.Routes.FirstOrDefault();
                if (r == null || r.Polyline.Positions == null || !r.Polyline.Positions.Any()) return;

                this.SetRouteData(route, r);

                var routeOptions = new PolylineOptions();

                if (route.Color != Color.Default)
                {
                    routeOptions.InvokeColor(route.Color.ToAndroid().ToArgb());
                }
                if (route.LineWidth > 0)
                {
                    routeOptions.InvokeWidth(route.LineWidth);
                }
                routeOptions.Add(r.Polyline.Positions.Select(i => i.ToLatLng()).ToArray());

                this._routes.Add(route, this._googleMap.AddPolyline(routeOptions));

                if (this.FormsMap.RouteCalculationFinishedCommand != null && this.FormsMap.RouteCalculationFinishedCommand.CanExecute(route))
                {
                    this.FormsMap.RouteCalculationFinishedCommand.Execute(route);
                }
            }
            finally
            {
                if ((routeData == null || routeData.Status != GmsDirectionResultStatus.Ok) && this.FormsMap.RouteCalculationFailedCommand != null)
                {
                    if (this.FormsMap.RouteCalculationFailedCommand.CanExecute(route))
                    {
                        this.FormsMap.RouteCalculationFailedCommand.Execute(route);
                    }
                }
            }
        }
		public void HandleDirectionPointsResult(List<LatLng> directionPoints, LatLng startLocation, LatLng endLocation)
		{
			var line = new PolylineOptions();
		    line.InvokeWidth(8);
		    line.InvokeColor(global::Android.Graphics.Color.Blue);
			int i = 0;
		    foreach (var point in directionPoints)
		    {
		        line.Add(point);


		    }

		    if (mMap != null)
		    {

				CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
				builder.Target(startLocation);
				builder.Zoom(10);

				builder.Bearing(0);
				builder.Tilt(0);
				CameraPosition cameraPosition = builder.Build();
				CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                this.RunOnUiThread(() =>
                {
						mMap.Clear();

						// Uses a colored icon.
						 mMap.AddMarker(new MarkerOptions()
							.SetPosition(startLocation)
							.SetTitle(GeoStartAddress)
							.SetSnippet("Population: Unknown")
							.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed)));

						mMap.AddMarker(new MarkerOptions()
							.SetPosition(endLocation)
							.SetTitle(GeoEndAddress)
							.SetSnippet("Population: Unknown")
							.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed)));
					
						var img = BitmapDescriptorFactory.FromResource (Resource.Drawable.badge_victoria);
						var groundOverlayOptions1 = new GroundOverlayOptions ()
							.Position (startLocation, 1600, 1600)
							.InvokeImage (img);
						var mapOverlay1 = mMap.AddGroundOverlay(groundOverlayOptions1);


						//Randomly adding Map OVerlays on the map.
						foreach (var point in directionPoints)
						{
							i++;
							if (i > 520) {
								i = 0;

								var image = BitmapDescriptorFactory.FromResource (Resource.Drawable.balloon_overlay_focused);
								var groundOverlayOptions = new GroundOverlayOptions ()
									.Position (point, 2000, 2000)
									.InvokeImage (image);
								var mapOverlay = mMap.AddGroundOverlay(groundOverlayOptions);
								var checadd = mapOverlay;

							}
						}
						mMap.AnimateCamera(cameraUpdate);
						var drawline = mMap.AddPolyline(line);    
                });
		        
		    }

		   // return 1;
		}
예제 #18
0
        private void createLines()
        {
            try
            {
                var androidMapView = (MapView)Control;
                var formsMap = (Xam.Plugin.MapExtend.Abstractions.MapExtend)Element;
                //androidMapView.Map.Clear();
                PolylineOptions line = new PolylineOptions();
                line.InvokeColor(global::Android.Graphics.Color.Blue);
                foreach (var item in formsMap.polilenes)
                {

                    LatLng pos = new LatLng(item.Latitude, item.Longitude);
                    line.Add(pos);
                }
                androidMapView.Map.AddPolyline(line);
            }
            catch (Exception e)
            {

                throw e;
            }
        }
예제 #19
0
        public MapRoute(GoogleMap map, ServerResponse.ResponseRoute[] responseRoutes)
        {
            var numberOfRoutes = responseRoutes.Length * 2 - 1;
            _map = map;
            _mapRoutes = new List<Polyline>();
            _mapStations = new List<Marker>();
            var l = 1;
            for (var i = 0; i < numberOfRoutes; i++)
            {
                // Create new partial route.
                if (i % 2 == 0)
                {
                    // Choose color;
                    Color color = Color.DodgerBlue;

                    // Create polyline.
                    var polyline = new PolylineOptions();
                    polyline.InvokeWidth(4f);
                    polyline.InvokeColor(color);

                    // Add points to polyline.
                    int k = i / 2;
                    ServerResponse.ResponseRoute responseRoute = responseRoutes[k];
                    for (var j = 0; j < responseRoute.pointsId.Length; j++)
                    {
                        string stationId = responseRoute.pointsId[j];
                        Station station = App.Database.GetStationById(stationId);
                        if (station != null && station.latitude != 0f && station.longitude != 0f)
                        {
                            var latlng = new Android.Gms.Maps.Model.LatLng(station.latitude, station.longitude);
                            polyline.Add(latlng);
                            // Create marker.
                            var marker = new MarkerOptions();
                            marker.SetPosition(latlng);
                            marker.SetTitle(l++ + ". " + station.postName);
                            marker.Draggable(false);
                            marker.SetSnippet("ul. " + station.street + "\n"+ "linia: " + responseRoute.variantId);
                            _mapStations.Add(_map.AddMarker(marker));
                        }
                    }

                    // Add polyline to map.
                    _mapRoutes.Add(_map.AddPolyline(polyline));
                }
                // Create connection between two routes.
                else
                {
                    // Choose color;
                    Color color = Color.LightSkyBlue;

                    // Create polyline.
                    PolylineOptions polyline = new PolylineOptions();
                    polyline.InvokeWidth(3f);
                    polyline.InvokeColor(color);

                    // Add points to polyline (closest, non 0f points).
                    // Last point from previous route.
                    int k = i / 2;
                    for (var j = 0; j < responseRoutes[k].pointsId.Length; j++)
                    {
                        string prevStationId = responseRoutes[k].pointsId[responseRoutes[k].pointsId.Length - 1 - j];
                        Station prevStation = App.Database.GetStationById(prevStationId);
                        if (prevStation != null && prevStation.latitude != 0f && prevStation.longitude != 0f)
                        {
                            polyline.Add(new Android.Gms.Maps.Model.LatLng(prevStation.latitude, prevStation.longitude));
                            break;
                        }
                    }
                    // 1st point from next route.
                    k++;
                    for (var j = 0; j < responseRoutes[k].pointsId.Length; j++)
                    {
                        string nextStationId = responseRoutes[k].pointsId[j];
                        Station nextStation = App.Database.GetStationById(nextStationId);
                        if (nextStation != null && nextStation.latitude != 0f && nextStation.longitude != 0f)
                        {
                            polyline.Add(new Android.Gms.Maps.Model.LatLng(nextStation.latitude, nextStation.longitude));
                            break;
                        }
                    }

                    // Add polyline to map.
                    _mapRoutes.Add(_map.AddPolyline(polyline));
                }
            }
        }
예제 #20
0
 private Polyline AddPolyline(PolylineOptions option)
 {
     var polyline = NativeMap.AddPolyline(option);
     polyline.Color = option.Color;
     polyline.Width = option.Width;
     return polyline;
 }
예제 #21
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);
			Inicializa_MapFragment ();
			//Definimos las ciudades en las cuales pondremos nuestros marcadores en el mapa
			MisCiudades.Add ( new Ciudad_Marca ("MÉXICO D.F.","En su forma abreviada México, D. F., es la capital y sede de los poderes federales de los Estados Unidos Mexicanos.",new LatLng (19.430334, -99.13599),"p1"));
			MisCiudades.Add ( new Ciudad_Marca ("LEÓN","Es una ciudad mexicana localizada  en el Estado de Guanajuato,México, en la región del Bajío.",new LatLng ( 21.12806,-101.689163),"p2"));
			MisCiudades.Add ( new Ciudad_Marca ("LAGOS DE MORENO"," Es un municipio y la ciudad más grande y poblada de la Región denominada Los Altos de Jalisco, ubicados en el estado mexicano de Jalisco.",new LatLng ( 21.36453,-101.939076),"p3"));
			MisCiudades.Add ( new Ciudad_Marca ("GUADALAJARA","es una ciudad mexicana, capital del estado de Jalisco, así como principal localidad del área urbana denominada Zona Metropolitana de Guadalajara.",new LatLng ( 20.663626,-103.343754),"p4"));

			CargamosMarcadores ();

			Button btnLinea = FindViewById<Button> (Resource.Id.btnLinea);
			Button btnCirculo = FindViewById<Button> (Resource.Id.btnCirculo);
			Button btnPoligono = FindViewById<Button> (Resource.Id.btnPoligono);
			txtPosicion=(TextView) FindViewById (Resource.Id.txtPosicion);



			btnLinea.Click += delegate {
				PolylineOptions rectOptions = new PolylineOptions();
				if (mMap != null)
				{
					foreach (Ciudad_Marca ciudad in MisCiudades) 
					{
						rectOptions.Add (ciudad.Ubicacion );
					}

					rectOptions.InvokeColor(Color.Red.ToArgb());
					rectOptions.InvokeWidth(25);
					rectOptions.Geodesic(true) ;

					mMap.AddPolyline(rectOptions);
				}
			};

			btnCirculo.Click += delegate {
				if (mMap != null)
				{
					foreach (Ciudad_Marca ciudad in MisCiudades) 
					{
						CircleOptions circleOptions = new CircleOptions();
						circleOptions.InvokeCenter(ciudad.Ubicacion);
						circleOptions.InvokeRadius(10000);

						circleOptions.InvokeStrokeWidth(10);
						circleOptions.InvokeStrokeColor(Color.Blue.ToArgb() );

						Color micolorfill=Color.FromArgb(150,149,153,225);
						circleOptions.InvokeFillColor(micolorfill.ToArgb() );

						mMap.AddCircle(circleOptions);

					}
				}

			};

			btnPoligono.Click += delegate {
				if (mMap != null) {
					PolygonOptions Poligono = new PolygonOptions ();
					foreach (Ciudad_Marca ciudad in MisCiudades) {
						Poligono.Add (ciudad.Ubicacion);
					}

					Poligono.InvokeStrokeWidth(10);
					Poligono.InvokeStrokeColor(Color.Green.ToArgb ());

					Color micolorfill=Color.FromArgb(150,0,255,51);
					Poligono.InvokeFillColor(micolorfill.ToArgb() );

					mMap.AddPolygon (Poligono);
				}
			};


		}
예제 #22
0
 		public Task <List<PolylineOptions>> Filling (string data)
		{
			return Task.Run(() => {
				
			var polyLineOptions = new PolylineOptions ();
			var ListPolylineOptions = new List<PolylineOptions>();
			var jsonData = "";
				jsonData = data;
				var jObject = new JSONObject (jsonData);
				var parser = new PathJsonParser ();
				var ListCoords = parser.parse (jObject);

				if(ListCoords.Count > 0){
				for (int j = 0; j < ListCoords.Count; j++) {
					var listCoord = ListCoords[j];
					foreach(var list in listCoord)
					{
						polyLineOptions.Add (list);
					}
					polyLineOptions.InvokeWidth (5);
					polyLineOptions.InvokeColor (Color.Red);

				}
				ListPolylineOptions.Add(polyLineOptions);
				}

				return ListPolylineOptions;
			});
		}
예제 #23
0
        void UpdateMap(TripPoint point, bool updateCamera = true)
        {
            if (map == null)
                return;
            //Get trail position or current potion to move car
            var latlng = point == null
                ? viewModel?.CurrentPosition?.ToLatLng()
                : point.ToLatLng();
            Activity?.RunOnUiThread(() =>
            {
                UpdateCar(latlng);
                driveLine?.Remove();
                var polyOptions = new PolylineOptions();

                if (allPoints == null)
                {
                    allPoints = viewModel.CurrentTrip.Points.ToLatLngs();
                }
                else if (point != null)
                {
                    allPoints.Add(point.ToLatLng());
                }

                polyOptions.Add(allPoints.ToArray());

                if (!driveLineColor.HasValue)
                    driveLineColor = new Color(ContextCompat.GetColor(Activity, Resource.Color.recording_accent));

                polyOptions.InvokeColor(driveLineColor.Value);
                driveLine = map.AddPolyline(polyOptions);
                if (updateCamera)
                    UpdateCamera(latlng);
            });
        }