Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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.
            }
        }
Ejemplo n.º 3
0
        private void InitLocationClient()
        {
            _LocaltionClient = new AMapLocationClient(ApplicationContext);
            _LocaltionClient.SetLocationListener(new MapLocaltionListenerImp(OnLocationChanged));

            //创建定位设置
            var option = new AMapLocationClientOption();

            //设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。
            option.SetInterval(15 * 1000);
            //单位是毫秒,默认30000毫秒,建议超时时间不要低于8000毫秒。
            option.SetHttpTimeOut(10 * 1000);
            //关闭缓存机制
            option.SetLocationCacheEnable(false);
            if (null != _LocaltionClient)
            {
                _LocaltionClient.SetLocationOption(option);
                _LocaltionClient.StopLocation();
                _LocaltionClient.StartLocation();
            }
        }
Ejemplo n.º 4
0
        private void InitLocation()
        {
            //声明mlocationClient对象

            LocationClient = new AMapLocationClient(this);
            //初始化定位参数
            AMapLocationClientOption mLocationOption = new AMapLocationClientOption();

            //设置定位监听
            LocationClient.SetLocationListener(new LocationListener(this));
            //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
            mLocationOption.SetLocationMode(AMapLocationClientOption.AMapLocationMode.HightAccuracy);
            //设置定位间隔,单位毫秒,默认为2000ms
            mLocationOption.SetInterval(2000);
            //设置定位参数
            LocationClient.SetLocationOption(mLocationOption);
            // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,
            // 注意设置合适的定位时间的间隔(最小间隔支持为1000ms),并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后,在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
            //启动定位
            LocationClient.StartLocation();
        }
        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());
        }