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

怎么办个人网站网络营销推广公司简介

怎么办个人网站,网络营销推广公司简介,怎么用手机做网站教程,电脑有了外网是不是就可以做网站毫无疑问,要想使用LocationManager就必须要先获取到它的实例,我们可以调用Context的getSystemService()方法获取到。getSystemService()方法接收一个字符串参数用于确定获取系统的哪个服务,这里传入Context.LOCATION_SERVICE即可。因此&#…

  毫无疑问,要想使用LocationManager就必须要先获取到它的实例,我们可以调用Context的getSystemService()方法获取到。getSystemService()方法接收一个字符串参数用于确定获取系统的哪个服务,这里传入Context.LOCATION_SERVICE即可。因此,获取LocationManager的实例就可以写成: 

LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

Android 中一般有三种位置 提供器可供选择,GPS_PROVIDER、NETWORK_PROVIDER和PASSIVE_PROVIDER。其中前两种使用的比较多,分别表示使用GPS定位和使用网络定位。这两种定位方式各有特点,GPS定位的精准度比较高,但是非常耗电,而网络定位的精准度稍差,但耗电量比较少。 我们应该根据自己的实际情况来选择使用哪一种位置提供器,当位置精度要求非常高的时候,最好使用GPS_PROVIDER,而一般情况下,使用NETWORK_PROVIDER会更加得划算。 

 将选择好的位置提供器传入到getLastKnownLocation()方法中,就可以得到一个Location对象,如下所示: 

String provider = LocationManager.NETWORK_PROVIDER; Location location = locationManager.getLastKnownLocation(provider); 
 这个Location对象中包含了经度、纬度、海拔等一系列的位置信息,然后从中取出我们所关心的那部分数据即可。 
 如果有些时候你想让定位的精度尽量高一些,但又不确定GPS定位的功能是否已经启用,这个时候就可以先判断一下有哪些位置提供器可用,如下所示: 

List<String> providerList = locationManager.getProviders(true);

 可以看到,getProviders()方法接收一个布尔型参数,传入true就表示只有启用的位置提供器才会被返回。之后再从providerList中判断是否包含GPS定位的功能就行了。 

 另外,调用getLastKnownLocation()方法虽然可以获取到设备当前的位置信息,但是用户是完全有可能带着设备随时移动的,那么我们怎样才能在设备位置发生改变的时候获取到最新的位置信息呢?不用担心,LocationManager还提供了一个requestLocationUpdates()方法,只要传入一个LocationListener的实例,并简单配置几个参数就可以实现上述功能了,写法如下: 

mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, new LocationListener() {@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {// TODO Auto-generated method stub}@Overridepublic void onProviderEnabled(String provider) {// TODO Auto-generated method stub}@Overridepublic void onProviderDisabled(String provider) {// TODO Auto-generated method stub}@Overridepublic void onLocationChanged(Location location) {// TODO Auto-generated method stub}});

  这里requestLocationUpdates()方法接收四个参数,第一个参数是位置提供器的类型,第二个参数是监听位置变化的时间间隔,以毫秒为单位,第三个参数是监听位置变化的距离间隔,以米为单位,第四个参数则是LocationListener监听器。这样的话,LocationManager每隔5秒钟会检测一下位置的变化情况,当移动距离超过10米的时候,就会调用LocationListener的onLocationChanged()方法,并把新的位置信息作为参数传入。 

整个例子的代码如下所示

package com.test.locationtest;import java.util.List;import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;public class MainActivity extends Activity {private TextView tvLocation;private LocationManager locationManager;private String provider;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tvLocation = (TextView) findViewById(R.id.tv_location);locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);List<String> allProvider = locationManager.getProviders(true);if (allProvider.contains(LocationManager.GPS_PROVIDER)) {provider = LocationManager.GPS_PROVIDER;} else if (allProvider.contains(LocationManager.NETWORK_PROVIDER)) {provider = LocationManager.NETWORK_PROVIDER;} else {Toast.makeText(this, "请打开GPS 或者 数据", Toast.LENGTH_SHORT).show();return;}Location location = locationManager.getLastKnownLocation(provider);Log.d("MainActivity", "显示位置");showLocation(location);}LocationListener locationListener = new LocationListener() {@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {// TODO Auto-generated method stub}@Overridepublic void onProviderEnabled(String provider) {// TODO Auto-generated method stub}@Overridepublic void onProviderDisabled(String provider) {// TODO Auto-generated method stub}@Overridepublic void onLocationChanged(Location location) {showLocation(location);}};@Overrideprotected void onDestroy() {super.onDestroy();if (locationManager != null) {// 关闭程序时将监听器移除locationManager.removeUpdates(locationListener);}}private void showLocation(Location location) {//这里获取location 可能为空  while (location == null) {locationManager.requestLocationUpdates(provider, 2000, (float) 0.1,locationListener);}if (location != null) {String currentPosition = "latitude is " + location.getLatitude()+ "\n" + "longitude is " + location.getLongitude();Log.d("MainActivity", currentPosition);tvLocation.setText(currentPosition);}}
}

获取Location 可能为空 ,可以自己百度解决下


还需要增加以下权限

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permission android:name="android.permission.INTERNET"/>




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

相关文章:

  • 优秀企业网站首页上海网络营销有限公司
  • wordpress变论坛南昌百度搜索排名优化
  • 跨境电商需要投资多少seo网上培训多少钱
  • 建设银行的官方网站电脑版百度免费咨询
  • 网站到期只续域名不续空间能打开吗长沙百度推广运营公司
  • 网页设计和网页美工优化人员是什么意思
  • 营销推广方法中国seo第一人
  • 动画制作专业学校排名aso关键词优化工具
  • 火鸟门户系统seo排名优化首页
  • 网站 做 app开发工具网店seo名词解释
  • 成品网站建设咨询在线之家
  • 打开网站的语音播报怎么做app推广注册放单平台
  • 天津 网站建设今天刚刚发生的新闻台湾新闻
  • 安阳县高级中学厦门seo关键词排名
  • 基于wap的企业网站设计与实现网络广告文案范文
  • 个人备案可以建企业网站吗重庆网站建设维护
  • 网站建设行业赚钱么seo泛目录培训
  • 合肥商城网站建设北京官方seo搜索引擎优化推荐
  • 出版社网站建设平台推广引流
  • p2p网站开发思路方案做运营的具体做什么
  • 品牌建设对企业发展的重要性木卢seo教程
  • wordpress操作卡卡的系统优化app最新版
  • 苏州网站建设哪家公司好百度快照客服
  • 怎么不能安装wordpress关键词seo优化排名公司
  • 网站如何做百度权重企业网站seo案例
  • 做网站应该会什么seo文章代写一篇多少钱
  • 商业网站制作价格营销型网站内容
  • 网站页面多大seo搜索引擎的优化
  • 怎么让织梦网站适合手机nba赛季排名
  • 内部网站建设公司重庆seo推广运营