【问题标题】:get a map view for a specific location I choose it latitude&longitude获取特定位置的地图视图我选择它纬度经度
【发布时间】:2013-09-05 13:46:04
【问题描述】:

我想在我的活动中放置一张地图,通过选择纬度和经度来显示特定位置

    public class conactus extends Activity{
    private GoogleMap map;
    private LatLng myLoc;
    double latitude=34.112924;
    double longitude=35.650288;

    @SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_connectus);
        MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
        fm.getMap();
        Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());  

        try {

            List<Address> ad = geoCoder.getFromLocation(latitude, longitude,1);

            if (ad.size() > 0) {
                myLoc = new LatLng(
                        (int) (ad.get(0).getLatitude() * 1E6), 
                        (int) (ad.get(0).getLongitude() * 1E6));
                map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                CameraUpdate update = CameraUpdateFactory.newLatLngZoom(myLoc, 14);
                map.animateCamera(update);
            }    
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    }

【问题讨论】:

标签: java android google-maps google-maps-api-3


【解决方案1】:

首先尝试在真实设备上调试,有时 gmap 不会在模拟器中显示。 还要检查您的地图调试密钥是否有效。 另外,如果还是有问题,使用this 指南非常简单。

【讨论】:

    【解决方案2】:

    您应该将fm.getMap(); 更改为map = fm.getMap();

    【讨论】:

      猜你喜欢
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      相关资源
      最近更新 更多