当前位置: 首页 > news >正文

电脑在哪里制作网站营销推广方案怎么写

电脑在哪里制作网站,营销推广方案怎么写,吉林省公务员网络培训网站,温室大棚建设 网站及排名转卖文章目录 前言一、实现步骤二、使用步骤1.服务启动工具类2.实现LocationService 总结 前言 在android开发中地图和定位是很多软件不可或缺的内容,这些特色功能也给人们带来了很多方便。定位一般分为三种发方案:即GPS定位、Google网络定位以及基站定位。…

文章目录

  • 前言
  • 一、实现步骤
  • 二、使用步骤
    • 1.服务启动工具类
    • 2.实现LocationService
  • 总结


前言

在android开发中地图和定位是很多软件不可或缺的内容,这些特色功能也给人们带来了很多方便。定位一般分为三种发方案:即GPS定位、Google网络定位以及基站定位。


本文分别介绍GPS定位、以及基于Google的网络Wifi定位的详细步骤,(小米手机获取位置信息locationManager.getLastKnownLocation(provider)的Location一直为空,查了资料换了种获取手机getProviders的方式就可以了)

一、实现步骤

一般来说我们实现原生定位的流程大概是:先判断有无权限》有权限启动一个LocationSrevice去获取定位》最后携带所需的定位信息返回,进行开发。

二、使用步骤

1.服务启动工具类

代码如下(示例):大概步骤如下,权限请求可自定义开发关键的是LocationService

/*** 获取定位*/
public class MyLocationManager implements LocationService.LocationCallBack {private Activity context;private OnLocationListener onLocationListener;private String[] stringsLocation = new String[]{Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_COARSE_LOCATION};@Overridepublic void Location_Return(double Location_latitude, double Location_longitude, String province, String city, String area, String featureName) {onLocationListener.OnLocation(Location_latitude, Location_longitude, province, city, area, featureName);}public interface OnLocationListener {void OnLocation(double Location_latitude, double Location_longitude, String province, String city, String area, String featureName);}public void setOnLocationListener(OnLocationListener onLocationListener) {this.onLocationListener = onLocationListener;}public MyLocationManager(@NonNull Activity context) {this.context = context;if (!XXPermissions.isGranted(context, stringsLocation)) {MessageDialog codeDialog = new MessageDialog(context, "位置信息权限使用说明", "为确保你能在******内使用位置信息******,******需要获取你的位置信息权限。允许后,你可以随时通过手机系统设置对授权进行管理。", "取消", "去授权");codeDialog.setCancelable(false);codeDialog.show();codeDialog.setOnSumbitTextCodeListener(() -> {doMainPermission();codeDialog.dismiss();});codeDialog.setOnCancelListener(() -> {codeDialog.dismiss();});} else {initData();}}private void doMainPermission() {XXPermissions.with(context).permission(stringsLocation).request(new OnPermissionCallback() {@Overridepublic void onGranted(@NonNull List<String> permissions, boolean allGranted) {if (allGranted) {initData();}}@Overridepublic void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {if (doNotAskAgain) {}}});}@SuppressLint("MissingPermission")private void initData() {// 创建 Service 实例LocationService myService = new LocationService();// 设置回调接口myService.setCallback(this);// 启动 Service 并执行操作Intent serviceIntent = new Intent(context, LocationService.class);context.startService(serviceIntent);}
}
/**-------------------------/
不要忘了注册<serviceandroid:name=".utils.LocationService"android:enabled="true"android:exported="false" />

2.实现LocationService

代码如下(示例):

/*** 获取定位服务*/
public class LocationService extends Service {private LocationManager locationManager;private MyLocationListener myLocationListener;public static LocationCallBack mCallBack = null;public interface LocationCallBack {void Location_Return(double Location_latitude, double Location_longitude, String province, String city, String area, String featureName);}public void setCallback(LocationCallBack callback) {this.mCallBack = callback;}@Overridepublic IBinder onBind(Intent intent) {return null;}@SuppressLint("MissingPermission")@Overridepublic void onCreate() {super.onCreate();myLocationListener = new MyLocationListener();locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);try {GPSLocation();} catch (Exception e) {if (ObjectUtils.isNotEmpty(locationManager) && ObjectUtils.isNotEmpty(myLocationListener))locationManager.removeUpdates(myLocationListener); // 停止所有的定位服务stopSelf();  // 获取到经纬度以后,停止该service}}class MyLocationListener implements LocationListener {// 位置改变时获取经纬度@Overridepublic void onLocationChanged(Location location) {if (ObjectUtils.isNotEmpty(location)) {toGeocoder(location);}}// 状态改变时@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {}// 提供者可以使用时@Overridepublic void onProviderEnabled(String provider) {}// 提供者不可以使用时@Overridepublic void onProviderDisabled(String provider) {}}@SuppressLint("MissingPermission")private Location getLastKnownLocation(LocationManager locationManager) {List<String> providers = locationManager.getProviders(true);Location bestLocation = null;for (String provider : providers) {Location l = locationManager.getLastKnownLocation(provider);if (l == null) {continue;}if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {bestLocation = l;}}return bestLocation;}@SuppressLint("MissingPermission")private void GPSLocation() {Location location = getLastKnownLocation(locationManager);if (location != null) {//不为空,显示地理位置经纬度String longitude = "Longitude:" + location.getLongitude();String latitude = "Latitude:" + location.getLatitude();LogUtils.e("Location:" + longitude + latitude);toGeocoder(location);} else {LogUtils.e("Location:" + "Location为空");if (ObjectUtils.isNotEmpty(locationManager) && ObjectUtils.isNotEmpty(myLocationListener))locationManager.removeUpdates(myLocationListener); // 停止所有的定位服务stopSelf();  // 获取到经纬度以后,停止该service}}@SuppressLint("MissingPermission")private void toGeocoder(Location location) {String province = "";String city = "";String area = "";String featureName = "";try {Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);if (ObjectUtils.isNotEmpty(addresses) && 0 < addresses.size()) {Address address = addresses.get(0);if (ObjectUtils.isNotEmpty(address)) {// 获取省份(province)province = address.getAdminArea();// 获取城市(City)city = address.getLocality();// 获取区县(area)area = address.getSubLocality();//  获取详细地址featureName = address.getFeatureName();// 获取街道地址String addressLine = address.getAddressLine(0);// 打印详细地址信息LogUtils.e("AddressInfo", "province: " + province);LogUtils.e("AddressInfo", "City: " + city);LogUtils.e("AddressInfo", "area: " + area);LogUtils.e("AddressInfo", "FeatureName: " + featureName);LogUtils.e("AddressInfo", "Address Line: " + addressLine);}mCallBack.Location_Return(location.getLatitude(), location.getLongitude(), province, city, area, featureName);}if (ObjectUtils.isNotEmpty(locationManager) && ObjectUtils.isNotEmpty(myLocationListener))locationManager.removeUpdates(myLocationListener); // 停止所有的定位服务stopSelf();  // 获取到经纬度以后,停止该service} catch (Exception e) {if (ObjectUtils.isNotEmpty(locationManager) && ObjectUtils.isNotEmpty(myLocationListener))locationManager.removeUpdates(myLocationListener); // 停止所有的定位服务stopSelf();  // 获取到经纬度以后,停止该servicee.printStackTrace();}}@SuppressLint("MissingPermission")@Overridepublic void onDestroy() {super.onDestroy();if (ObjectUtils.isNotEmpty(locationManager) && ObjectUtils.isNotEmpty(myLocationListener))locationManager.removeUpdates(myLocationListener); // 停止所有的定位服务stopSelf();}}

该处使用原生定位获取经纬度、省市县等数据的详细步骤。


总结

以上就是今天要讲的使用Android原生获取定位内容,本文详细展现了完整流程,希望对大家会有帮助,公司如果有实力大可不必如此,直接给第三方地图交钱就好了,毕竟人家又快又准(本文仅仅适用于只需经纬度或者地址信息的同学,有地图展现需求的只能想别的方法了哈哈)。

http://www.tj-hxxt.cn/news/32396.html

相关文章:

  • 某企业网站网页设计模板竞价推广营销
  • 代码生成器在线衡阳seo优化报价
  • 王野天女演员葛优照片搜索引擎优化方法与技巧
  • 番禺低价网站建设电视剧百度搜索风云榜
  • 近的网站在线客服系统泰安做网站公司哪家比较好
  • 深圳宝安网站推广适合员工的培训课程
  • wordpress分类目录title2020 惠州seo服务
  • 石岩附近做网站公司湖北荆门今日头条
  • 点开图片跳到网站怎么做产品如何做线上推广
  • 佛山网站制作做多少钱企业管理培训
  • 做阿胶上什么网站比较好万网域名注册信息查询
  • 做网站流程seo全称英文怎么说
  • 网站后台左侧导航折叠效果打不开站长工具查询seo
  • 做爰全过程网站免费的视频兰州seo优化公司
  • 深圳市网站备案需求百度一下百度主页
  • 国外设计案例网站项目营销推广策划
  • 石家庄外贸网站制作网站建设知名公司
  • 江苏连云港最新疫情广州seo网站推广公司
  • 微信微网站怎么进入生成关键词的软件免费
  • 做网站认证违法吗营销策略的思路
  • 网站开发属于商标哪个类别朔州seo
  • DW建设网站过程中出现的问题网络视频营销平台
  • 网站建设模式有哪些内容有做网站的吗
  • 做律师网站sem推广计划
  • 贵州网络科技有限公司windows优化大师下载
  • 百度蜘蛛开发网站石家庄seo网站管理
  • 金山区做网站吗seo运营招聘
  • 做推送的网站有哪些摘抄一则新闻
  • 沈阳城市建设招生网站搜索热词排行榜
  • 政府网站信息发布建设方案推广渠道有哪些平台