Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的纬度和经度变化,地图未显示_Android - Fatal编程技术网

android中的纬度和经度变化,地图未显示

android中的纬度和经度变化,地图未显示,android,Android,android中的纬度和经度变化,地图未显示 package net.learn2develop.GoogleMaps; import java.io.IOException; import java.util.*; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import co

android中的纬度和经度变化,地图未显示

package net.learn2develop.GoogleMaps;

import java.io.IOException;
import java.util.*;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.MapView.LayoutParams;
import android.app.LocalActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MapsActivity extends MapActivity {
    MapView mapView;
    MapController mc;
    GeoPoint p;
    double latPoint, lngPoint;
    LocationManager myManager;


class MapOverlay extends com.google.android.maps.Overlay
{
    @Override

    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());

            Geocoder geoCoder = new Geocoder(
                getBaseContext(), Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocation(
                    p.getLatitudeE6()  / 1E6, 
                    p.getLongitudeE6() / 1E6, 1);

                String add = "";
                if (addresses.size() > 0) 
                {
                    for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); 
                         i++)
                       add += addresses.get(0).getAddressLine(i) + "\n";
                }
                Log.e("address", add);

                Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
            }
            catch (IOException e) {                
                e.printStackTrace();
            }   
            return true;
        }
        else                
            return false;
    }        

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapView);
    LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
    View zoomView = mapView.getZoomControls();

    zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mapView.displayZoomControls(true);

    mc = mapView.getController();
     LocationManager myManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());


    mc.setZoom(10);

    //---Add a location marker---
    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);   

    mapView.invalidate();

}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

class myLocationListener implements LocationListener {

    public void ListLocationUpdater() {
    }

    @Override
    public void onLocationChanged(Location loc) {
        if (myManager != null) {
            // List list = myManager.getAllProviders();
            String param = (String) myManager.getProviders(true).get(0);
            loc = myManager.getLastKnownLocation(param);
            if (loc != null) {
                latPoint = loc.getLatitude();
                lngPoint = loc.getLongitude();
                                    p = new GeoPoint((int) (latPoint * 1E6), (int) (lngPoint * 1E6));

    mc.animateTo(p);                    Log.e("RootDrawApplication",String.valueOf(latPoint)+"  , "+String.valueOf(lngPoint));

            } else
                Log.e("GoogleMaps ", "Error: Location  is null");
        } else
            Log.e("GoogleMaps ", "Error: Location Manager is null");
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}
package net.learn2develope.GoogleMaps;
导入java.io.IOException;
导入java.util.*;
导入com.google.android.maps.GeoPoint;
导入com.google.android.maps.MapActivity;
导入com.google.android.maps.MapController;
导入com.google.android.maps.MapView;
导入com.google.android.maps.Overlay;
导入com.google.android.maps.MapView.LayoutParams;
导入android.app.LocalActivityManager;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.graphics.Canvas;
导入android.graphics.Point;
导入android.location.Address;
导入android.location.Geocoder;
导入android.location.location;
导入android.location.LocationListener;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.MotionEvent;
导入android.view.view;
导入android.widget.LinearLayout;
导入android.widget.Toast;
公共类MapsActivity扩展了MapActivity{
地图视图;
地图控制器;
地质点p;
双latPoint,lngPoint;
地点经理我的经理;
类MapOverlay扩展了com.google.android.maps.Overlay
{
@凌驾
公共布尔onTouchEvent(MotionEvent事件,MapView MapView)
{   
//---当用户抬起手指时---
如果(event.getAction()==1){
地理点p=mapView.getProjection().fromPixels(
(int)event.getX(),
(int)event.getY();
地理编码器地理编码器=新地理编码器(
getBaseContext(),Locale.getDefault();
试一试{
列表地址=geoCoder.getFromLocation(
p、 getLatitudeE6()/1E6,
p、 getLongitudeE6()/1E6,1);
字符串add=“”;
如果(地址.size()>0)
{

对于(int i=0;i创建一个背景线程并检查那里的gps数据。 并使用LocationListener:

private final LocationListener locationListener = new LocationListener() {
      public void onLocationChanged(Location l) {
         TextView tv = new TextView(gpstracker.this);
         tv.setText("lat: " + l.getLatitude() + "\nlon: " + l.getLongitude());
         setContentView(tv);
      }
      ...

还可以使用以下代码帮助…

将位置侦听器添加到位置管理器:

myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                    0, new myLocationListener());
这样,myLocationListener将实现locationListener接口,并在onLocationChangedFunction中更改位置

public class myLocationListener implements LocationListener {

    public ListLocationUpdater() {
    }

    @Override
    public void onLocationChanged(Location location) {
        //assign location here
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}

我有一个疑问是线程每秒钟运行一次…我对线程了解不多,以前也没有在线程中工作。请更正我如何使用它,请帮助我。如果我将我的代码放在OnLocationChange()中对于myLocationListener类,它将提供错误。请更正我将上述代码放在何处。我通过了我的代码,因为没有生成应用程序。它不是未生成(生成错误是:myLocationListener无法解析为类型,3个快速修复1)更改为LocationListener(anroid.listener)2)创建一个类myLocationListener 3)修复项目设置。下一行myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,new myLocationListener())也会出现相同的错误;myLocationListener是无法解析的类型。它不是生成的。请帮助我查看您的代码。我发现您的myManager未在中声明为类的字段。请将其声明为字段而不是局部变量,然后放松我们在这里。错误已清除,但未显示地图,而仅显示蓝屏。我编辑我的问题并粘贴我的code和logcat请修改并帮助我。