Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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 Google map V2提供了以前接触过的位置的地址_Android_Google Maps_Location_Reverse Geocoding - Fatal编程技术网

Android Google map V2提供了以前接触过的位置的地址

Android Google map V2提供了以前接触过的位置的地址,android,google-maps,location,reverse-geocoding,Android,Google Maps,Location,Reverse Geocoding,我正在我的应用程序中使用Google map v2。我正在单击的位置放置标记。当我再次单击地图时,privios标记消失,新标记添加。当我检查地址时,它会显示已删除标记的地址。i、 e它包含最后一次触摸的位置。 请帮帮我。如何删除地址以及删除的标记。这是我的密码 public class Map extends FragmentActivity { GoogleMap gMap; static int loginCheck = 0; GeoPoint p, currentLocationPixe

我正在我的应用程序中使用Google map v2。我正在单击的位置放置标记。当我再次单击地图时,privios标记消失,新标记添加。当我检查地址时,它会显示已删除标记的地址。i、 e它包含最后一次触摸的位置。 请帮帮我。如何删除地址以及删除的标记。这是我的密码

public class Map extends FragmentActivity {
GoogleMap gMap;
static int loginCheck = 0;
GeoPoint p, currentLocationPixels;
ConnectionDetector conDec;
ArrayList<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
SharedPreferences prefs;
LatLng latLng;
MarkerOptions markerOptions;
EditText desc;
String addressText = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.map);

    prefs = getApplicationContext().getSharedPreferences("jam",
            MODE_PRIVATE);

    conDec = new ConnectionDetector(this);

    SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.mapView);
    gMap = smf.getMap();

    gMap.setMyLocationEnabled(true);
    gMap.getUiSettings().setCompassEnabled(true);
    // gMap.setTrafficEnabled(true);


    gMap.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng arg0) {

            // Getting the Latitude and Longitude of the touched location
            latLng = arg0;

            // Clears the previously touched position
            gMap.clear();
            addressText=null;

            // Animating to the touched position
            // gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));

            int caller = getIntent().getIntExtra("button", 0);
            System.out.println(caller);
            switch (caller) {
            case R.id.btMap:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_darkblue)).title(addressText));
                break;
            case R.id.imageButton1:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_bue)).title(addressText));
                break;
            case R.id.imageButton2:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_green)).title(addressText));
                break;
            case R.id.imageButton3:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_light)).title(addressText));
                break;
            case R.id.imageButton4:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_purple)).title(addressText));
                break;
            case R.id.imageButton5:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_red)).title(addressText));
                break;
            case R.id.imageButton6:
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_yellow)).title(addressText));
                break;
            }

            // Creating a marker
            // markerOptions = new MarkerOptions();

            // Setting the position for the marker
            // markerOptions.position(latLng);

            // Placing a marker on the touched position
            // gMap.addMarker(markerOptions);

            // Adding Marker on the touched location with address
            new ReverseGeocodingTask(getBaseContext()).execute(latLng);
        }
    });

    // ** Hide By Gaurav
    // gMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
    // @Override
    // public void onInfoWindowClick(Marker marker) {
    // System.out.println(marker.getPosition().latitude);
    //
    // Intent i = new Intent(Map.this, Detail.class);
    // i.putExtra("lat", "" + marker.getPosition().latitude);
    // i.putExtra("lng", "" + marker.getPosition().longitude);
    // i.putExtra("title", marker.getTitle());
    // i.putExtra("desc", marker.getSnippet());
    // startActivity(i);
    // }
    // });
    getInfo();

    CameraPosition cp = new CameraPosition.Builder()
            .target(new LatLng(Double.parseDouble("30.7353"), Double
                    .parseDouble("76.7911"))).zoom(16).build();
    gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
}

// ** Gaurav Work Start Here
private class ReverseGeocodingTask extends AsyncTask<LatLng, Void, String> {
    Context mContext;

    public ReverseGeocodingTask(Context context) {
        super();
        mContext = context;
    }

    // Finding address using reverse geocoding
    @Override
    protected String doInBackground(LatLng... params) {
        Geocoder geocoder = new Geocoder(mContext);
        double latitude = params[0].latitude;
        double longitude = params[0].longitude;
        List<Address> addresses = null;
        //String addressText = "";
        try {
            addresses = geocoder.getFromLocation(latitude, longitude, 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (addresses != null && addresses.size() > 0) {
            Address address = addresses.get(0);

            addressText = String.format(
                    "%s, %s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address
                            .getAddressLine(0) : "", address.getLocality(),
                    address.getCountryName());
        }

        return addressText;
    }


    // @Override
    // protected void onPostExecute(String addressText) {
    //
    // // This will be displayed on taping the marker
    // markerOptions.title(addressText);
    //
    // // Placing a marker on the touched position
    // gMap.addMarker(markerOptions);
    //
    // }
}}
公共类映射扩展了碎片活动{
谷歌地图;
静态int-loginCheck=0;
地理点p,当前位置像素;
连接检测器;
ArrayList aList=新的ArrayList();
共享引用优先权;
LatLng LatLng;
标记选项标记选项;
编辑文本描述;
字符串addressText=“”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
prefs=getApplicationContext().GetSharedReferences(“jam”,
模式(私人),;
conDec=新的连接检测器(本);
SupportMapFragment smf=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.mapView);
gMap=smf.getMap();
gMap.setMyLocationEnabled(真);
gMap.getUiSettings().setCompassEnabled(true);
//gMap.setTrafficEnabled(真);
setOnMapClickListener(新的OnMapClickListener(){
@凌驾
点击时的公共无效(LatLng arg0){
//获取被触摸位置的纬度和经度
latLng=arg0;
//清除先前触摸的位置
gMap.clear();
addressText=null;
//设置动画到被触摸的位置
//gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
int caller=getIntent().getIntExtra(“按钮”,0);
System.out.println(调用者);
交换机(调用者){
案例R.id.btMap:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_darkblue)).title(addressText));
打破
案例R.id.imageButton1:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_bue)).title(addressText));
打破
案例R.id.imageButton2:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_green)).title(addressText));
打破
案例R.id.imageButton3:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_light)).title(addressText));
打破
案例R.id.imageButton4:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_purple)).title(addressText));
打破
案例R.id.imageButton5:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_red)).title(addressText));
打破
案例R.id.imageButton6:
gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.addMarker(新的MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_yellow)).title(addressText));
打破
}
//创建标记
//markerOptions=新的markerOptions();
//设置标记器的位置
//标记选项位置(板条);
//在触摸的位置放置标记
//gMap.addMarker(标记选项);
//在带有地址的触摸位置上添加标记
新建ReverseGeocodingTask(getBaseContext()).execute(latLng);
}
});
//**由高拉夫隐藏
//gMap.setOnInfoWindowClickListener(新的OnInfoWindowClickListener(){
//@覆盖
//公用无效信息窗口单击(标记){
//System.out.println(marker.getPosition().latitude);
//
//意向i=新意向(Map.this,Detail.class);
//i.putExtra(“lat”,“marker.getPosition().纬度”);
//i.putExtra(“lng”,“marker.getPosition().longitude”);
//i.putExtra(“title”,marker.getTitle());
//i.putExtra(“desc”,marker.getSnippet());
//星触觉(i);
// }
// });
getInfo();
CameraPosition cp=新建CameraPosition.Builder()
.目标(新车床(双精度)双精度(“30.7353”),双精度
.parseDouble(“76.7911”)).zoom(16.build();
gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
}
//**Gaurav工作从这里开始
私有类ReverseGeocodingTask扩展了AsyncTask{
语境;
公共反向分类任务(上下文){
超级();
mContext=上下文;
}
//使用反向地理编码查找地址
@凌驾
受保护管柱后台(LatLng…参数){
Geocoder Geocoder=新的Geocoder(mContext);
双纬度=参数[0]。纬度;
双经度=参数[0]。经度;
列表地址=空;
//字符串addressText=“”;
试一试{
地址=地理编码器.getFromLocation(纬度,经度,1);
}捕获(IOE异常){
e、 printStackTrace();
}
if(addresses!=null&&addresses.size()>0){
地址地址
public class Map extends FragmentActivity {
GoogleMap gMap;
static int loginCheck = 0;
GeoPoint p, currentLocationPixels;
ConnectionDetector conDec;
ArrayList<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
SharedPreferences prefs;
LatLng latLng;
MarkerOptions markerOptions;
EditText desc;
String selectedLocAddress;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.map);

    prefs = getApplicationContext().getSharedPreferences("jam",
            MODE_PRIVATE);

    conDec = new ConnectionDetector(this);

    SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.mapView);
    gMap = smf.getMap();

    gMap.setMyLocationEnabled(true);
    gMap.getUiSettings().setCompassEnabled(true);
    // gMap.setTrafficEnabled(true);

    // ** Gaurav Works Start Here

    gMap.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng arg0) {

            // Getting the Latitude and Longitude of the touched location
            latLng = arg0;

            // Clears the previously touched position
            gMap.clear();

            // Animating to the touched position
            gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));


            // Adding Marker on the touched location with address
            new ReverseGeocodingTask(getBaseContext()).execute(latLng);
        }
    });

    // ** Hide By Gaurav
     gMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
     public void onInfoWindowClick(Marker marker) {
     System.out.println(marker.getPosition().latitude);

     Intent i = new Intent(Map.this, Detail.class);

     startActivity(i);
     }
     });
    getInfo();

    CameraPosition cp = new CameraPosition.Builder()
            .target(new LatLng(Double.parseDouble("30.7353"), Double
                    .parseDouble("76.7911"))).zoom(16).build();
    gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
}

// ** Gaurav Work Start Here
private class ReverseGeocodingTask extends AsyncTask<LatLng, Void, String> {
    Context mContext;

    public ReverseGeocodingTask(Context context) {
        super();
        mContext = context;
    }

    // Finding address using reverse geocoding
    @Override
    protected String doInBackground(LatLng... params) {
        Geocoder geocoder = new Geocoder(mContext);
        double latitude = params[0].latitude;
        double longitude = params[0].longitude;
        List<Address> addresses = null;
        String addressText = "";
        try {
            addresses = geocoder.getFromLocation(latitude, longitude, 1);
        if (addresses != null && addresses.size() > 0) {
            Address address = addresses.get(0);

            addressText = String.format("%s, %s, %s",address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                    address.getLocality(),address.getCountryName());
        }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return addressText;
    }


    // @Override
    protected void onPostExecute(String addressText) {
        selectedLocAddress = addressText;

        int caller = getIntent().getIntExtra("button", 0);
        System.out.println(caller);
        switch (caller) {
        case R.id.btMap:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_darkblue)).title(selectedLocAddress));
            System.out.println("selectedLocAddress");
            break;
        case R.id.imageButton1:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_bue)).title(selectedLocAddress));
            break;
        case R.id.imageButton2:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_green)).title(selectedLocAddress));
            break;
        case R.id.imageButton3:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_light)).title(selectedLocAddress));
            break;
        case R.id.imageButton4:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_purple)).title(selectedLocAddress));
            break;
        case R.id.imageButton5:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_red)).title(selectedLocAddress));
            break;
        case R.id.imageButton6:
            gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_yellow)).title(selectedLocAddress));
            break;
        }
    //
    // // This will be displayed on taping the marker
    // markerOptions.title(addressText);
    //
    // // Placing a marker on the touched position
    // gMap.addMarker(markerOptions);
    //
}
}