Beispiel #1
0
        private void InitMapView()
        {
            var aMap = AMapView.Map;

            // 显示实时交通状况
            aMap.TrafficEnabled = true;
            //地图模式可选类型:MAP_TYPE_NORMAL,MAP_TYPE_SATELLITE,MAP_TYPE_NIGHT
            // 卫星地图模式
            aMap.MapType = AMap.MapTypeSatellite;

            var uiSettings = aMap.UiSettings;

            //设置默认定位按钮是否显示,非必需设置。
            uiSettings.MyLocationButtonEnabled = true;
            //控制比例尺控件是否显示
            uiSettings.ZoomControlsEnabled = false;
            //显示指南针
            uiSettings.CompassEnabled = true;

            MyLocationStyle myLocationStyle = new MyLocationStyle();

            //定位一次,且将视角移动到地图中心点
            myLocationStyle.InvokeMyLocationType(MyLocationStyle.LocationTypeLocate);
            //设置是否显示定位小蓝点
            myLocationStyle.ShowMyLocation(true);
            //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
            myLocationStyle.InvokeInterval(2000);
            //设置定位蓝点的Style
            aMap.MyLocationStyle = myLocationStyle;

            aMap.SetOnMyLocationChangeListener(new AMapLocationChange(this));

            // 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false
            aMap.MyLocationEnabled = true;
        }
Beispiel #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            //3dmap相关
            mapView = new MapView(this);
            mapView.OnCreate(savedInstanceState);

            //定位相关
            mLocationClient = new AMapLocationClient(this);
            mLocationClient.SetLocationListener(new AMapLocationListener());
            mLocationClient.StartLocation();
            myLocationStyle = new MyLocationStyle();
            myLocationStyle.InvokeInterval(2000);
            mapView.Map.MyLocationStyle   = myLocationStyle;
            mapView.Map.MyLocationEnabled = true;
            myLocationStyle.InvokeMyLocationType(MyLocationStyle.LocationTypeFollow);
            myLocationStyle.ShowMyLocation(true);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
Beispiel #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            mapView = FindViewById <MapView>(Resource.Id.mapView);
            button  = FindViewById <Button>(Resource.Id.myButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };

            mapView.OnCreate(savedInstanceState);

            locationClient       = new AMapLocationClient(this.ApplicationContext);
            locationClientOption = new AMapLocationClientOption();
            locationClientOption.SetWifiActiveScan(false);
            locationClientOption.SetMockEnable(true);
            locationClientOption.SetLocationMode(AMapLocationClientOption.AMapLocationMode.DeviceSensors);

            locationClient.SetLocationOption(locationClientOption);

            locationClient.Location += AMapLocationClient_Location;

            if (aMap == null)
            {
                aMap = mapView.Map;
                if (lastCamera == null)
                {
                    lastCamera = CameraUpdateFactory.NewLatLngZoom(new LatLng(lastPositionArray[0], lastPositionArray[1]), 15);
                }
                aMap.MoveCamera(lastCamera);

                if (locationStyle == null)
                {
                    locationStyle = new MyLocationStyle();
                    locationStyle.ShowMyLocation(true);
                    locationStyle.InvokeMyLocationType(MyLocationStyle.LocationTypeFollow);
                }

                aMap.SetMyLocationStyle(locationStyle);
                aMap.MyLocationEnabled = true;

                aMap.UiSettings.MyLocationButtonEnabled = true; //设置默认定位按钮是否显示,非必需设置。
                locationClient.StartLocation();
                //aMap.
            }
        }
Beispiel #4
0
        private void SetLocation()
        {
            aMap.SetLocationSource(this);                   // 设置定位监听
            aMap.UiSettings.MyLocationButtonEnabled = true; // 设置默认定位按钮是否
            aMap.MyLocationEnabled = true;                  // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
            //aMap.SetMyLocationType(AMap.LOCATION_TYPE_LOCATE);//设置定位的类型为跟随模式,3D地图才有;
            // 自定义系统定位小蓝点
            MyLocationStyle myLocationStyle = new MyLocationStyle();

            myLocationStyle.InvokeMyLocationIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.Icon));
            // 设置小蓝点的图标
            myLocationStyle.InvokeStrokeColor(Android.Graphics.Color.Red);                      // 设置圆形的边框颜色
            myLocationStyle.InvokeRadiusFillColor(Android.Graphics.Color.Argb(100, 0, 0, 180)); // 设置圆形的填充颜色
            myLocationStyle.InvokeStrokeWidth(1.0f);                                            // 设置圆形的边框粗细
            aMap.SetMyLocationStyle(myLocationStyle);
            aMap.MapType = AMap.MapTypeNormal;
        }
Beispiel #5
0
        private void setUpMap()
        {
            LatLng SHANGHAI = new LatLng(31.238068, 121.501654);

            aMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(SHANGHAI, 14));
            aMap.MapType = AMap.MapTypeNormal;

            var pins = myAMapPage.Pins;

            Drawable d      = Resources.GetDrawable(Resource.Drawable.red_location);
            Bitmap   bitmap = ((BitmapDrawable)d).Bitmap;
            LatLng   latLng1;

            foreach (UserTaskEntInfo pin in pins)
            {
                latLng1 = new LatLng(pin.Longitude ?? 31.238068, pin.Latitude ?? 121.501654);
                var markOption = new MarkerOptions();
                markOption.InvokeIcon(BitmapDescriptorFactory.FromBitmap(bitmap));
                markOption.InvokeTitle(pin.Name);
                markOption.InvokePosition(latLng1);
                var fix = aMap.AddMarker(markOption);
                fix.ShowInfoWindow();
            }

            aMap.SetLocationSource(this);                   // 设置定位监听
            aMap.UiSettings.MyLocationButtonEnabled = true; // 设置默认定位按钮是否显示
            aMap.MyLocationEnabled = true;                  // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
            //aMap.SetMyLocationType(AMap.LOCATION_TYPE_LOCATE);//设置定位的类型为跟随模式,3D地图才有;

            // 自定义系统定位小蓝点
            MyLocationStyle myLocationStyle = new MyLocationStyle();

            myLocationStyle.InvokeMyLocationIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.location_marker)); // 设置小蓝点的图标
            myLocationStyle.InvokeStrokeColor(Android.Graphics.Color.Black);                                               // 设置圆形的边框颜色
            myLocationStyle.InvokeRadiusFillColor(Android.Graphics.Color.Argb(100, 0, 0, 180));                            // 设置圆形的填充颜色
            myLocationStyle.InvokeStrokeWidth(1.0f);                                                                       // 设置圆形的边框粗细
            aMap.SetMyLocationStyle(myLocationStyle);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            //3dmap相关
            mapView = new MapView(this);
            mapView.OnCreate(savedInstanceState);

            //定位相关
            mLocationClient = new AMapLocationClient(this);
            mLocationClient.SetLocationListener(new AMapLocationListener());
            mLocationClient.StartLocation();
            myLocationStyle = new MyLocationStyle();
            myLocationStyle.InvokeInterval(2000);
            mapView.Map.MyLocationStyle   = myLocationStyle;
            mapView.Map.MyLocationEnabled = true;
            myLocationStyle.InvokeMyLocationType(MyLocationStyle.LocationTypeFollow);
            myLocationStyle.ShowMyLocation(true);

            //导航相关
            navi = AMapNavi.GetInstance(this);
            navi.AddAMapNaviListener(this);
            navi.SetEmulatorNaviSpeed(260);//260km/h
            naviRelativeLayout = LayoutInflater.Inflate(Resource.Layout.NaviLayout, null) as Android.Widget.RelativeLayout;
            mAMapNaviView      = naviRelativeLayout.FindViewById <AMapNaviView>(Resource.Id.navi_view);
            mAMapNaviView.SetAMapNaviViewListener(new AMapNaviViewListener());
            mAMapNaviView.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            MessagingCenter.Subscribe <object>(this, SearchPage.QueryWeather, sender =>
            {
                //检索参数为城市和天气类型,实况天气为WEATHER_TYPE_LIVE、天气预报为WEATHER_TYPE_FORECAST
                var mquery         = new WeatherSearchQuery("北京", WeatherSearchQuery.WeatherTypeLive);
                var mweathersearch = new WeatherSearch(this);
                mweathersearch.SetOnWeatherSearchListener(new OnWeatherSearchListener());
                mweathersearch.Query = mquery;
                mweathersearch.SearchWeatherAsyn(); //异步搜索
            });

            MessagingCenter.Subscribe <object>(this, TrackPage.StartTrack, sender =>
            {
                //猎鹰相关
                mAMapTrackClient = new AMapTrackClient(this);
                //上报周期,采用默认,不设置
                //mAMapTrackClient.SetInterval
                //本地缓存大小,采用默认,不设置
                //mAMapTrackClient.SetCacheSize
                //定位模式,采用默认,不设置
                //mAMapTrackClient.SetLocationMode

                //执行一次,创建serviceid即可
                //await (Xamarin.Forms.Application.Current as App).CreateServiceId();
                //await (Xamarin.Forms.Application.Current as App).ServiceId();
                //137618从ServiceId()获取后复制的
                mAMapTrackClient.QueryTerminal(new QueryTerminalRequest(137618, "id1234"), new OnTrackListener(137618, "id1234", mAMapTrackClient));
            });

            LoadApplication(new App());
        }