Ejemplo n.º 1
0
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            extendedMap = (ExtendedMap)Element;
            mapView = Control as MapView;
            map = mapView.Map;

            map.MarkerClick+= HandleMarkerClick;

            // Pin tıklanınca sağalta açılan menüyü engellemek için
            map.UiSettings.MapToolbarEnabled = true;
            map.UiSettings.MyLocationButtonEnabled = true;

            if (extendedMap.isOverlayNeeded) {
                LatLng southwest = new LatLng (extendedMap.sw.Latitude, extendedMap.sw.Longitude);
                LatLng northeast = new LatLng (extendedMap.ne.Latitude, extendedMap.ne.Longitude);

                LatLngBounds bounds = new LatLngBounds (southwest, northeast);

                string url = extendedMap.overlayURL;//"http://www.mgm.gov.tr/mobile/mblhrt/data/radar/MAX--_6100_P00.png";

                Bitmap objBitmap = GetImageBitmapFromUrl (url);

                BitmapDescriptor objBitmapDescriptor = BitmapDescriptorFactory.FromBitmap (objBitmap);
                GroundOverlayOptions objGroundOverlayOptions = new GroundOverlayOptions ().PositionFromBounds (bounds)/*.Position (objMapPosition, 100000)*/.InvokeImage (objBitmapDescriptor);

                map.AddGroundOverlay (objGroundOverlayOptions);

                //For freeing memory
                objBitmap.Recycle ();
            }

            for (int i = 0; i < extendedMap.pinDatas.Count; i++) {
                var markerWithIcon = new MarkerOptions ();
                markerWithIcon.SetPosition (new LatLng (extendedMap.pinDatas[i].lat, extendedMap.pinDatas[i].lng));
                markerWithIcon.SetTitle (i.ToString());
                /*markerWithIcon.SetTitle ("aa");
                markerWithIcon.SetSnippet ("bb");*/
                int resID = Resources.GetIdentifier (extendedMap.pinDatas [i].icon, "drawable" , "com.app1001.bluemart");
                //System.Diagnostics.Debug.WriteLine (resID);
                markerWithIcon.SetIcon(BitmapDescriptorFactory.FromResource(resID));
                map.AddMarker (markerWithIcon);
            }

            //Add Pins

            //map.SetInfoWindowAdapter(this);
            map.UiSettings.RotateGesturesEnabled = false;
        }
Ejemplo n.º 2
0
        public static LatLngBounds extendLimits(LatLngBounds bounds, int ratio)
        {
            double extendedLongitude = Math.Abs(bounds.Northeast.Longitude
                                 - bounds.Southwest.Longitude) / ratio;

            double extendedLatitude = Math.Abs(bounds.Northeast.Latitude
                                 - bounds.Southwest.Latitude) / ratio;

            LatLng topRight = null;
            LatLng bottomLeft = null;

            // Longitudes
            double topRightLongitude = bounds.Northeast.Longitude + extendedLongitude;
            double bottomLeftLongitude = bounds.Southwest.Longitude - extendedLongitude;

            // latitudes
            double topRightLatitude = bounds.Northeast.Latitude + extendedLatitude;
            double bottomLeftLatitude = bounds.Southwest.Latitude - extendedLatitude;

            topRight = new LatLng(topRightLatitude, topRightLongitude);
            bottomLeft = new LatLng(bottomLeftLatitude, bottomLeftLongitude);

            return new LatLngBounds(bottomLeft, topRight);
        }
Ejemplo n.º 3
0
 // gets all gyms at the given location and calculate a radius
 public async Task<JsonValue> GetPlacesAsJSON(double lat, double lng, LatLngBounds llb)
 {
     var radius = LatLngDist.distance(llb.Northeast.Latitude, llb.Northeast.Longitude, llb.Southwest.Latitude, llb.Southwest.Longitude, 'K') * 1000 / 2;
     Log.Debug("JSON", radius + "");
     return await GetPlacesAsJSON(lat, lng, radius);
 }
Ejemplo n.º 4
0
                void UpdateMap(bool result)
                {
                    if (GroupEntries.Count > 0)
                    {
                        // update our list and display
                        SearchResultPrefix.Text = ConnectStrings.GroupFinder_Neighborhood;

                        (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(0);

                        // for the map, ensure it's valid, because Google Play can fail
                        if (Map != null)
                        {
                            Map.Clear( );
                            MarkerList.Clear( );

                            Android.Gms.Maps.Model.LatLngBounds.Builder builder = new Android.Gms.Maps.Model.LatLngBounds.Builder();

                            // add the source position
                            Android.Gms.Maps.Model.MarkerOptions markerOptions = new Android.Gms.Maps.Model.MarkerOptions();
                            Android.Gms.Maps.Model.LatLng        pos           = new Android.Gms.Maps.Model.LatLng(SourceLocation.Latitude, SourceLocation.Longitude);
                            markerOptions.SetPosition(pos);
                            markerOptions.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
                            builder.Include(pos);

                            Android.Gms.Maps.Model.Marker marker = Map.AddMarker(markerOptions);
                            MarkerList.Add(marker);

                            for (int i = 0; i < GroupEntries.Count; i++)
                            {
                                // add the positions to the map
                                markerOptions = new Android.Gms.Maps.Model.MarkerOptions();
                                pos           = new Android.Gms.Maps.Model.LatLng(GroupEntries[i].Latitude, GroupEntries[i].Longitude);
                                markerOptions.SetPosition(pos);
                                markerOptions.SetTitle(GroupEntries[i].Name);
                                markerOptions.SetSnippet(string.Format("{0:##.0} {1}", GroupEntries[i].DistanceFromSource, ConnectStrings.GroupFinder_MilesSuffix));

                                builder.Include(pos);

                                marker = Map.AddMarker(markerOptions);
                                MarkerList.Add(marker);
                            }

                            Android.Gms.Maps.Model.LatLngBounds bounds = builder.Build( );

                            int paddingInPixels = Math.Min(View.Width, (int)(View.Height * .1f));

                            CameraUpdate camPos = CameraUpdateFactory.NewLatLngBounds(bounds, paddingInPixels);
                            Map.AnimateCamera(camPos);

                            // show the info window for the first (closest) group
                            MarkerList[1].ShowInfoWindow( );
                        }
                    }
                    else
                    {
                        if (result == true)
                        {
                            // send the analytic and update our list
                            SearchResultPrefix.Text       = ConnectStrings.GroupFinder_NoGroupsFound;
                            SearchResultNeighborhood.Text = string.Empty;

                            (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(-1);

                            // validate the map before using. Google Play can error
                            if (Map != null)
                            {
                                // no groups found, so move the camera to the default position
                                Android.Gms.Maps.Model.LatLng defaultPos = new Android.Gms.Maps.Model.LatLng(ConnectConfig.GroupFinder_DefaultLatitude, ConnectConfig.GroupFinder_DefaultLongitude);
                                CameraUpdate camPos = CameraUpdateFactory.NewLatLngZoom(defaultPos, ConnectConfig.GroupFinder_DefaultScale_Android);
                                Map.AnimateCamera(camPos);
                            }
                        }
                        else
                        {
                            // there was actually an error. Let them know.
                            SearchResultPrefix.Text       = ConnectStrings.GroupFinder_NetworkError;
                            SearchResultNeighborhood.Text = string.Empty;
                        }
                    }
                }
Ejemplo n.º 5
0
		void PostDelayInitMap (LatLngBounds bounds)
		{
			if (initTry == 4)
				return;

			mapView.PostDelayed (() => {
				initTry++;
				if (mapView.Width == 0)
					PostDelayInitMap (bounds);
				else
					googleMap.MoveCamera (CameraUpdateFactory.NewLatLngBounds (bounds, 0));
			}, 250);
		}
        /// <summary>
        /// Sets the route calculation data
        /// </summary>
        /// <param name="route">The PCL route</param>
        /// <param name="routeResult">The rourte api result</param>
        private void SetRouteData(TKRoute route, GmsRouteResult routeResult)
        {
            var latLngBounds = new LatLngBounds(
                    new LatLng(routeResult.Bounds.SouthWest.Latitude, routeResult.Bounds.SouthWest.Longitude),
                    new LatLng(routeResult.Bounds.NorthEast.Latitude, routeResult.Bounds.NorthEast.Longitude));

            var apiSteps = routeResult.Legs.First().Steps;
            var steps = new TKRouteStep[apiSteps.Count()];
            var routeFunctions = (IRouteFunctions)route;

            
            for (int i = 0; i < steps.Length; i++)
            {
                steps[i] = new TKRouteStep();
                var stepFunctions = (IRouteStepFunctions)steps[i];
                var apiStep = apiSteps.ElementAt(i);

                stepFunctions.SetDistance(apiStep.Distance.Value);
                stepFunctions.SetInstructions(apiStep.HtmlInstructions);
            }
            routeFunctions.SetSteps(steps);
            routeFunctions.SetDistance(routeResult.Legs.First().Distance.Value);
            routeFunctions.SetTravelTime(routeResult.Legs.First().Duration.Value);
            routeFunctions.SetBounds(
                MapSpan.FromCenterAndRadius(
                    latLngBounds.Center.ToPosition(),
                    Distance.FromKilometers(
                        new Position(latLngBounds.Southwest.Latitude, latLngBounds.Southwest.Longitude)
                        .DistanceTo(
                            new Position(latLngBounds.Northeast.Latitude, latLngBounds.Northeast.Longitude)))));

        }
 public AndroidViewportFilter(LatLngBounds viewportBounds)
 {
     this.ViewportBounds = viewportBounds;
 }
Ejemplo n.º 8
0
        private void ZoomMapTo(IEnumerable<LatLng> locations)
        {
            LatLngBounds locationBoundary = null;

            if (locations != null || locations.Count () != 0)
                locationBoundary = new LatLngBounds (locations.First (), locations.First ());

            if (locations.Count () > 1)
                foreach (var loc in locations)
                    locationBoundary.Including (loc);

            map.MoveCamera (CameraUpdateFactory.NewLatLngZoom (locationBoundary.Center, 10));
        }