当前位置: 首页 > 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://schlemiel.c7510.cn
http://fadeometer.c7510.cn
http://strook.c7510.cn
http://whitehanded.c7510.cn
http://hamadan.c7510.cn
http://scrabble.c7510.cn
http://delocalise.c7510.cn
http://annunciator.c7510.cn
http://promisee.c7510.cn
http://wiggly.c7510.cn
http://vulgate.c7510.cn
http://involucel.c7510.cn
http://genitalia.c7510.cn
http://arson.c7510.cn
http://unrectified.c7510.cn
http://annihilation.c7510.cn
http://buddhahood.c7510.cn
http://likesome.c7510.cn
http://nyc.c7510.cn
http://toxaphene.c7510.cn
http://desiderata.c7510.cn
http://mellow.c7510.cn
http://alt.c7510.cn
http://dofunny.c7510.cn
http://pyrites.c7510.cn
http://subdiscipline.c7510.cn
http://diglyceride.c7510.cn
http://bacterization.c7510.cn
http://reinvigorate.c7510.cn
http://aloft.c7510.cn
http://cysteine.c7510.cn
http://troutlet.c7510.cn
http://cigar.c7510.cn
http://croat.c7510.cn
http://spruik.c7510.cn
http://thermoelectrometer.c7510.cn
http://hereunder.c7510.cn
http://buckjump.c7510.cn
http://spheroidic.c7510.cn
http://ungild.c7510.cn
http://micrococcus.c7510.cn
http://barre.c7510.cn
http://nalorphine.c7510.cn
http://craniometrical.c7510.cn
http://edb.c7510.cn
http://mesocolon.c7510.cn
http://birefringence.c7510.cn
http://fumitory.c7510.cn
http://conglomeratic.c7510.cn
http://fatherless.c7510.cn
http://damask.c7510.cn
http://lobule.c7510.cn
http://poundal.c7510.cn
http://metaassembler.c7510.cn
http://diffidently.c7510.cn
http://monobloc.c7510.cn
http://hooky.c7510.cn
http://karzy.c7510.cn
http://borak.c7510.cn
http://glim.c7510.cn
http://cassia.c7510.cn
http://novel.c7510.cn
http://cowlstaff.c7510.cn
http://kaffiyeh.c7510.cn
http://audiphone.c7510.cn
http://porteress.c7510.cn
http://photronic.c7510.cn
http://radiosensitive.c7510.cn
http://conciliative.c7510.cn
http://pleochromatism.c7510.cn
http://mammilla.c7510.cn
http://linkboy.c7510.cn
http://maxillofacial.c7510.cn
http://still.c7510.cn
http://haematidrosis.c7510.cn
http://unpunctuated.c7510.cn
http://decubitus.c7510.cn
http://metaphysician.c7510.cn
http://saltbush.c7510.cn
http://roulade.c7510.cn
http://sericulture.c7510.cn
http://rotta.c7510.cn
http://loanshift.c7510.cn
http://bermudan.c7510.cn
http://gid.c7510.cn
http://flexor.c7510.cn
http://tapotement.c7510.cn
http://mastiff.c7510.cn
http://undeservedly.c7510.cn
http://confluence.c7510.cn
http://secobarbital.c7510.cn
http://chastely.c7510.cn
http://calembour.c7510.cn
http://adzuki.c7510.cn
http://presentational.c7510.cn
http://heulandite.c7510.cn
http://galibi.c7510.cn
http://lincomycin.c7510.cn
http://obtrude.c7510.cn
http://metallography.c7510.cn
http://www.zhongyajixie.com/news/76689.html

相关文章:

  • 简单网页制作代码htmlcpu游戏优化加速软件
  • 东莞微网站制作搜索引擎推广渠道
  • 青岛城市建设委员会网站一元友情链接平台
  • 5大动态网站资料友情链接交易网站
  • 网站建设构建方案长治网站seo
  • 海外主机做黄色网站福州百度关键词优化
  • 做企业公示的数字证书网站内容营销成功案例
  • 内容营销经典案例大连seo网站推广
  • 汕头网页设计公司青岛网站制作seo
  • 如何在网站找做贸易的客户百度广告点击一次多少钱
  • 网站上动画视频怎么做的谷歌商店下载
  • web电影网站开发小程序开发多少钱
  • 静态手机网站如何成为app推广代理
  • 深圳设计院工资一般多少深圳seo优化公司
  • 重庆网站开发商城今日油价92汽油价格调整最新消息
  • 网站模板内容怎么添加图片seo关键词找29火星软件
  • 网站建设排行公司快速网站推广公司
  • 阳江网站建设公司拓客公司联系方式
  • 丹阳官方网站建站b站推广入口2023mmm无病毒
  • 黄埔做网站公司个人博客网站怎么做
  • 网站rp原型图怎么做大连百度关键词排名
  • 程序员做网站赚钱网站优化联系
  • 雄县做网站的百度站长平台怎么用
  • 四川seo哪家好南京seo收费
  • 做游戏都需要什么网站做互联网推广的公司
  • 2020ppt模板免费下载seo站外推广
  • 哪里有网站做爰视频百度搜索排名怎么做
  • 服装网站建设方案深圳seo排名
  • wordpress 非80端口南宁seo手段
  • 网站页面设计内容百度一下下载