获得纬度和放大器;从Android的地址经度经度、纬度、放大器、地址

2023-09-05 06:03:13 作者:Initia(倾城)

我是试图让纬度和放大器;经度从地址,问题是,..当我只给出了比它给我正确的纬度和放大器城市名称;经度,当我给完整的地址(如国家,城市名称,街道号)比它不给我正确的纬度和放大器;经度...

感谢您的合作回应...

我的code是..

  //字符串addressStr =费萨拉巴德; ///这给我正确的地址
        字符串addressStr =Sainta奥古斯丁,佛罗里达州,4405大街甲;
          地理codeR地理codeR =新的地缘codeR(MapClass.this,Locale.getDefault());

          尝试 {
              名单<地址>地址=
          地理coder.getFromLocationName(addressStr,1);
              如果(addresses.size()大于0){
                 纬度= addresses.get(0).getLatitude();经度=
          addresses.get(0).getLongitude(); }

          }赶上(IOException异常E){// TODO自动生成的catch块
          e.printStackTrace(); }


        POS =新的经纬度(纬度,经度);
        googleMap.addMarker(新MarkerOptions()。图标​​(
                BitmapDesc​​riptorFactory
                        .defaultMarker(BitmapDesc​​riptorFactory.HUE_RED))
                .position(POS));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(POS,15));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(10),2000,NULL);
 

解决方案

我不它... :)

只有序列是不正确......

先给街道地址比城市名,比国家...它给我的地址,正确的纬度和经度..:)

和变化

 地理codeR地理codeR =新的地缘codeR(MapClass.this,Locale.getDefault());
 
看图填写A C两地的经纬度位置 1 A 经度 ,纬度 C 经度 ,纬度 2 在图中A B

 地理codeR地理codeR =新的地缘codeR(MapClass.this);
 

感谢,大家对你的时间......

i am try to get latitude & longitude from address , problem is that .. when i give only city name than it give me correct latitude & longitude and when i give complete address (like state , city name , street No.) than it do not give me correct latitude & longitude ...

thanks for your cooperative response ...

my code is ..

//String addressStr = "faisalabad";/// this give me correct address
        String addressStr = "Sainta Augustine,FL,4405 Avenue A";
          Geocoder geoCoder = new Geocoder(MapClass.this, Locale.getDefault());

          try {
              List<Address> addresses =
          geoCoder.getFromLocationName(addressStr, 1); 
              if (addresses.size() >  0) {
                 latitude = addresses.get(0).getLatitude(); longtitude =
          addresses.get(0).getLongitude(); }

          } catch (IOException e) { // TODO Auto-generated catch block
          e.printStackTrace(); }


        pos = new LatLng(latitude, longtitude);
        googleMap.addMarker(new MarkerOptions().icon(
                BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_RED))
                .position(pos));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(pos, 15));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

解决方案

i don it ... :)

only sequence is incorrect ...

first give street address than city name and than state ... it give me correct latitude and longitude from address .. :)

and change

Geocoder geoCoder = new Geocoder(MapClass.this, Locale.getDefault());

to

Geocoder geoCoder = new Geocoder(MapClass.this);

thanks, all of you for your time ...