コード例 #1
0
        public static Community IsInCyclesCommunity(LatLng pointLatLng)
        {
            var builder = new LatLngBounds.Builder();

            if (CyclesCommunities == null)
            {
                return(null);
            }
            foreach (Community community in CyclesCommunities)
            {
                if (community == null)
                {
                    continue;
                }
                foreach (LatLng latLngSet in community.PolygonCoordinates)
                {
                    if (latLngSet != null)
                    {
                        builder.Include(latLngSet);
                    }
                }

                LatLngBounds polygonBounds = builder.Build();
                if (polygonBounds.Contains(pointLatLng))
                {
                    return(community);
                }
            }

            return(null);
        }
コード例 #2
0
        public void LoadTrails()
        {
            latlng = _map.CameraPosition.Target;
            if (latlng.Latitude != 0 && latlng.Longitude != 0)
            {
                string startlat  = latlng.Latitude.ToString().Substring(0, 4);
                string startlong = latlng.Longitude.ToString().Substring(0, 4);

                DataAccess da = new DataAccess();
                DataTable  dt;

                if (da != null)
                {
                    dt = da.Load_Trail(startlat, startlong);

                    if (dt != null)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            if (_map != null)
                            {
                                //Separate latitude and longitude
                                string[] startCoord = row.ItemArray[3].ToString().Split(',');
                                double   startLat   = -1;
                                double   startLng   = -1;
                                try
                                {
                                    startLat = double.Parse(startCoord[0]);
                                    startLng = double.Parse(startCoord[1]);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Failed to parse start coordinates for a trail: MapActivity line 105");
                                    Console.WriteLine(ex.ToString());
                                }

                                if (startLat != -1 && startLng != -1)
                                {
                                    LatLngBounds bounds    = _map.Projection.VisibleRegion.LatLngBounds;
                                    LatLng       trailhead = new LatLng(startLat, startLng);

                                    //Load trails if they are in bounds of the zoom level
                                    if (bounds.Contains(trailhead))
                                    {
                                        LoadMarkers(bounds, trailhead, row);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static Community IsInCyclesCommunity(Location location)
        {
            var builder = new LatLngBounds.Builder();

            if (CyclesCommunities == null)
            {
                return(null);
            }
            if (CyclesCommunitiesPolygons != null && CyclesCommunitiesPolygons.Any())
            {
                foreach (LatLngBounds polygonBounds in CyclesCommunitiesPolygons)
                {
                    if (polygonBounds.Contains(new LatLng(location.Latitude, location.Longitude)))
                    {
                        return(CyclesCommunities[CyclesCommunitiesPolygons.IndexOf(polygonBounds)]);
                    }
                }
            }
            else
            {
                foreach (Community community in CyclesCommunities)
                {
                    if (community == null)
                    {
                        continue;
                    }
                    foreach (LatLng latLngSet in community.PolygonCoordinates)
                    {
                        if (latLngSet != null)
                        {
                            builder.Include(latLngSet);
                        }
                    }

                    LatLngBounds polygonBounds = builder.Build();
                    CyclesCommunitiesPolygons?.Add(polygonBounds);
                    if (polygonBounds.Contains(new LatLng(location.Latitude, location.Longitude)))
                    {
                        return(community);
                    }
                }
            }


            return(null);
        }
コード例 #4
0
        private void GoogleMap_CameraChange(object sender, GoogleMap.CameraChangeEventArgs e)
        {
            // Update bounds
            cameraBounds   = googleMap.Projection.VisibleRegion.LatLngBounds;
            cameraPosition = googleMap.CameraPosition;

            // Update lines visibility
            bool showBuses = e.Position.Zoom >= BusZoomLimit;

            foreach (Line line in TramUrWayApplication.Lines)
            {
                foreach (Route route in line.Routes)
                {
                    Polyline polyline;
                    if (!routeLines.TryGetValue(route, out polyline))
                    {
                        continue;
                    }

                    if (line.Type == LineType.Bus)
                    {
                        polyline.Visible = showBuses;
                    }
                }
            }

            // Update markers visibility
            foreach (var pair in transportMarkers)
            {
                bool visible = pair.Key.Route.Line.Type == LineType.Tram || showBuses;
                if (visible)
                {
                    visible = cameraBounds.Contains(pair.Value.Position);
                }

                pair.Value.Visible            = visible;
                markersVisibility[pair.Value] = visible;
            }
        }