gpt4 book ai didi

android - 此代码完美适用于 GPS,但我想使用 Wifi。该怎么做?

转载 作者:行者123 更新时间:2023-11-30 03:53:45 26 4
gpt4 key购买 nike

此代码与网络完美配合,但我需要进行 WiFi 测试 GPSwifi。所以我想同时检查 GPS wifi 和网络。对如何在 Android 应用程序中完成这项工作没有任何帮助。

    public class Map extends MapActivity {
double longitude;
double latitude;
MapView mapView;
private LocationManager mlocManager;
private LocationListener mlocListener;
private boolean gp;
Geocoder gd;
GeoPoint point;
List<Overlay> mapOverlays;
CustomItemizedOverlay itemizedOverlay;
MapController mapController;
private SportingSoccerApplication soccerApplication;
OverlayItem overlayitem;
SportingSoccerApplication soccerApplication2;
Drawable drawable;
RelativeLayout rv;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

setContentView(R.layout.map);

rv = (RelativeLayout) findViewById(R.id.relativeLayout1);
mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
gp = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
//Log.v("log_tag", gp + "");
//if (!gp == true) {
// turnGPSOn();
//}


mapView = (MapView) findViewById(R.id.mapview);
mapView.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

mapView.setBuiltInZoomControls(true);

}
});

mapView.setBuiltInZoomControls(true);

mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.markerdark);
itemizedOverlay = new CustomItemizedOverlay(drawable, this);

point = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
overlayitem = new OverlayItem(point, "", toString());
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapController = mapView.getController();
mapController.animateTo(point);

mapController.setZoom(14);

soccerApplication = (SportingSoccerApplication) getApplication();
}



@Override
protected void onResume() {
super.onResume();
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
mlocListener);

}



public class MyLocationListener implements LocationListener {

public void onLocationChanged(Location loc) {

mapView.getOverlays().clear();
mapView.postInvalidate();
mapOverlays.clear();
gd = new Geocoder(getApplicationContext(), Locale.getDefault());
longitude = loc.getLongitude();
latitude = loc.getLatitude();
Log.i("log_tag",longitude+"*******"+latitude);

/*try {
List<Address> place = gd
.getFromLocation(latitude, longitude, 1);
if(place.size() > 0) {
place.get(0).getLocality();
}
// Toast.makeText(getApplicationContext(), bus_no, 2).show();
} catch (IOException e) {
e.printStackTrace();
}*/
point = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));

Log.i("log_tag",latitude+"----"+longitude);
overlayitem = new OverlayItem(point, "", toString());
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapController.animateTo(point);
Log.v("log_tag", "u" + latitude + longitude + "");
soccerApplication.setLatitude(latitude);
soccerApplication.setLongitude(longitude);

}

public void onProviderDisabled(String provider) {

}

public void onProviderEnabled(String provider) {

}

public void onStatusChanged(String provider, int status, Bundle extras) {

}
}



protected boolean isRouteDisplayed() {
return false;
}

}

此代码适用于 android 网络基础,但我需要使用 GPS wifi ..

                <?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0bP2YJLhub2rGpXpOtkWFqcV3Qm5SS11Bl-cFyQ"
/>

package com.example.gpstest;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context mcontext;

public CustomItemizedOverlay(Drawable defaultMarker) {

super(boundCenterBottom(defaultMarker));

// TODO Auto-generated constructor stub
}

public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mcontext = context;
}

@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mapOverlays.get(i);
}

@Override
public int size() {
// TODO Auto-generated method stub
return mapOverlays.size();
}

@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mcontext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}

public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
populate();
}

}

最佳答案

你可以做一件事..在 Activity 启动时自动启动你的 WiFi

 protected void onStart() {
// TODO Auto-generated method stub
super.onStart();

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) {

wifiManager.setWifiEnabled(true);
}
}

将权限也放在 list 文件中:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"  />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

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

关于android - 此代码完美适用于 GPS,但我想使用 Wifi。该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13678367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com