android定位会出现的问题,android – 使用GPS_PROVIDER进行定位时出现问题
发布日期:2021-10-31 15:52:40 浏览次数:3 分类:技术文章

本文共 2076 字,大约阅读时间需要 6 分钟。

使用:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,

MINIMUM_TIME_BETWEEN_UPDATES,

MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, locationListener);

对于locationListener,您可以使用:

LocationListener locationListener = new LocationListener() {

public void onLocationChanged(Location location) {

// Called when a new location is found by the network location

// provider.

String message = String.format(

"New Location \n Longitude: %1$s \n Latitude: %2$s",

location.getLongitude(), location.getLatitude());

Toast.makeText(LbsGeocodingActivity.this, message,

Toast.LENGTH_LONG).show();

if (location != null) {

GeoPoint point2 = new GeoPoint(

(int) (location.getLatitude() * 1E6), (int) (location

.getLongitude() * 1E6));

// Toast.makeText(getBaseContext(),

// "Latitude: " + location.getLatitude() +

// " Longitude: " + location.getLongitude(),

// Toast.LENGTH_SHORT).show();

//

mapView.getController().animateTo(point2);

mapView.getController().setZoom(15);

List mapOverlays = mapView.getOverlays();

Drawable drawable = LbsGeocodingActivity.this.getResources()

.getDrawable(R.drawable.new3pin);

HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(

drawable, LbsGeocodingActivity.this);

point = new GeoPoint((int) (location.getLatitude() * 1E6),

(int) (location.getLongitude() * 1E6));

String address = convertPointToLocation(point);

String delims = ",";

String[] tokens = address.split(delims);

OverlayItem overlayitem = null;

if(tokens.length==1)

{

overlayitem = new OverlayItem(point,

"New Location", "Locality:"+"\nCity:"+"\nCountry: "+tokens[0]);

}

else if(tokens.length==2)

{

overlayitem = new OverlayItem(point,

"New Location", "Locality:"+"\nCity: "+tokens[0]+"\nCountry: "+tokens[1]);

}

else if(tokens.length==3)

{

overlayitem = new OverlayItem(point,

"New Location", "Locality: "+tokens[0]+"\nCity: "+tokens[1]+"\nCountry: "+tokens[2]);

}

else

{

overlayitem = new OverlayItem(point,

"New Location", address);

}

itemizedoverlay.addOverlay(overlayitem);

mapOverlays.clear();

mapOverlays.add(itemizedoverlay);

// mapView.invalidate();

}

}

我在我的代码中使用了它,它运行良好.

转载地址:https://blog.csdn.net/weixin_39987847/article/details/117511374 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android的sqlite使用外部,Android 使用外部已经建立好的sqlite数据库
下一篇:android 发布最新系统更新包,安卓升级包(安卓补丁包更新)

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月16日 09时21分53秒