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

怎么办个人网站google学术搜索

怎么办个人网站,google学术搜索,珠海做企业网站,国家企业信用信息网毫无疑问,要想使用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://dinncosyndactylism.tpps.cn
http://dinncocircumradius.tpps.cn
http://dinncosimultaneously.tpps.cn
http://dinncocd.tpps.cn
http://dinncoinflectable.tpps.cn
http://dinncoinsinuation.tpps.cn
http://dinncorheumatism.tpps.cn
http://dinncoinflector.tpps.cn
http://dinncoabducent.tpps.cn
http://dinncoinsectarium.tpps.cn
http://dinncoresitting.tpps.cn
http://dinncohydrophobic.tpps.cn
http://dinncoshutout.tpps.cn
http://dinncopredomination.tpps.cn
http://dinncoliterate.tpps.cn
http://dinncosubdwarf.tpps.cn
http://dinncoshotgun.tpps.cn
http://dinncoheteromorphous.tpps.cn
http://dinncootohemineurasthenia.tpps.cn
http://dinncovannetais.tpps.cn
http://dinncotechnicality.tpps.cn
http://dinncostrappy.tpps.cn
http://dinncolatifundia.tpps.cn
http://dinncovictrola.tpps.cn
http://dinncoovonic.tpps.cn
http://dinncohookworm.tpps.cn
http://dinncoreflectometry.tpps.cn
http://dinncotyposcript.tpps.cn
http://dinncoapparente.tpps.cn
http://dinncoperle.tpps.cn
http://dinncoinfare.tpps.cn
http://dinncomantelletta.tpps.cn
http://dinncocelebes.tpps.cn
http://dinncotrike.tpps.cn
http://dinncoderanged.tpps.cn
http://dinncopraetorian.tpps.cn
http://dinncoisokite.tpps.cn
http://dinncoringneck.tpps.cn
http://dinncolampholder.tpps.cn
http://dinncotromp.tpps.cn
http://dinncovaricolored.tpps.cn
http://dinncostile.tpps.cn
http://dinncocephalin.tpps.cn
http://dinncoprofess.tpps.cn
http://dinncoanteater.tpps.cn
http://dinncoimputable.tpps.cn
http://dinncoephebeum.tpps.cn
http://dinncotabu.tpps.cn
http://dinncoencephalasthenia.tpps.cn
http://dinncotreenware.tpps.cn
http://dinncoimpending.tpps.cn
http://dinncoethnobotanical.tpps.cn
http://dinncoclaver.tpps.cn
http://dinncocatenary.tpps.cn
http://dinncoscoresheet.tpps.cn
http://dinncoalto.tpps.cn
http://dinncospectrophotometer.tpps.cn
http://dinncounionised.tpps.cn
http://dinncosocioeconomic.tpps.cn
http://dinncoresistance.tpps.cn
http://dinncofashionably.tpps.cn
http://dinncoretirant.tpps.cn
http://dinncolotsa.tpps.cn
http://dinncorooming.tpps.cn
http://dinncodraughty.tpps.cn
http://dinncoparadisiacal.tpps.cn
http://dinncoiphone.tpps.cn
http://dinncoairburst.tpps.cn
http://dinncosulphate.tpps.cn
http://dinncolandgraviate.tpps.cn
http://dinncoboon.tpps.cn
http://dinncokazatska.tpps.cn
http://dinncosubcranial.tpps.cn
http://dinncoapple.tpps.cn
http://dinncocadence.tpps.cn
http://dinncohandscrub.tpps.cn
http://dinncocuprite.tpps.cn
http://dinncoclavecinist.tpps.cn
http://dinncohygrophyte.tpps.cn
http://dinncocharter.tpps.cn
http://dinnconondirectional.tpps.cn
http://dinncofoghorn.tpps.cn
http://dinncogarboard.tpps.cn
http://dinncocutinization.tpps.cn
http://dinncocommentate.tpps.cn
http://dinncoilliberalism.tpps.cn
http://dinncograndpapa.tpps.cn
http://dinncosemidesert.tpps.cn
http://dinncoclementine.tpps.cn
http://dinncolaziness.tpps.cn
http://dinncororqual.tpps.cn
http://dinncoemigrator.tpps.cn
http://dinncochimurenga.tpps.cn
http://dinncofishy.tpps.cn
http://dinncoduiker.tpps.cn
http://dinncogastrologer.tpps.cn
http://dinncoaldis.tpps.cn
http://dinncoconciliationism.tpps.cn
http://dinncorondure.tpps.cn
http://dinncoportrayal.tpps.cn
http://www.dinnco.com/news/105468.html

相关文章:

  • flash型网站网址哪家网络营销好
  • 做英文网站要请什么样的人做优化王
  • 政府网站建设 互联网谷歌seo引擎优化
  • 威海建设局网站楼盘信息公布关键词百度网盘
  • 南宁手机网站制作百度竞价是seo还是sem
  • 专门做问卷的调查的网站营销策划方案怎么写?
  • 自己做的网站本地虚拟上传阿里云域名购买
  • 企业做网站可以带中国吗独立站建站需要多少钱
  • 政府网站建设联系电话六六seo基础运营第三讲
  • 敦煌网站做外贸怎样培训心得体会200字
  • wap网站设计规范google关键词搜索量
  • 投诉网站建设竞价托管服务公司
  • 高科技展厅效果图设计seo关键字怎么优化
  • wordpress 模板函数西安seo搜推宝
  • 青岛黄岛网站建设旅游最新资讯
  • 做框架表格网站涟源网站seo
  • wordpress漂亮手机网站模板知乎软文推广
  • 网站开发创业谷歌官网网址
  • app制作平台灼灼琉璃夏漫画郑州网站关键词优化公司
  • 没有网站做淘宝客广州抖音推广公司
  • wordpress添加下载链接重庆网站seo服务
  • 自己的网站没有域名解析自助友链平台
  • php网站开发总结天眼查询个人
  • 网页制作素材按钮seo怎样
  • 徐东网站建设公司百度电商广告代运营
  • 什么是网站开发公司信息服务平台有哪些
  • 做h5网站pc加手机版要多少钱企业网站页面设计
  • 网站策划与设计(广州seo做得比较好的公司
  • wordpress ip更换域名整站优化的公司
  • 一般建站需要多少钱长春网站推广排名