获得纬度和放大器;从Android的地址经度 [英] Getting latitude & longitude from address in android

查看:133
本文介绍了获得纬度和放大器;从Android的地址经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

感谢您的合作回应...

我的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());
 

 地理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 ...

这篇关于获得纬度和放大器;从Android的地址经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆