如何在android应用程序中显示地点的位置

如何在android应用程序中显示地点的位置,android,google-maps,location,Android,Google Maps,Location,我正在寻找一种在android应用程序中显示位置的方法。我在MySQL数据库中存储了这个地方的经度和纬度坐标,现在我想检索它们(经度和纬度),并在应用程序中显示确切的位置。谢谢要使用纬度和经度获取位置详细信息,请使用以下代码 Geocoder geocoder; List<Address> addresses; geocoder = new Geocoder(this, Locale.getDefault()); addresses = geocoder.getFromLocati

我正在寻找一种在android应用程序中显示位置的方法。我在MySQL数据库中存储了这个地方的经度和纬度坐标,现在我想检索它们(经度和纬度),并在应用程序中显示确切的位置。谢谢

要使用纬度和经度获取位置详细信息,请使用以下代码

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());

addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5

String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL
Geocoder-Geocoder;
列出地址;
geocoder=新的geocoder(这个,Locale.getDefault());
地址=地理编码器。getFromLocation(纬度,经度,1);//这里1表示返回的最大位置结果,由它建议的1到5个文档决定
字符串地址=地址。get(0)。getAddressLine(0);//如果存在除“仅”之外的任何其他地址行,请通过getMaxAddressLineIndex()使用最大可用地址行进行检查
字符串city=addresses.get(0.getLocation();
字符串状态=addresses.get(0.getAdminArea();
字符串country=addresses.get(0.getCountryName();
字符串postalCode=addresses.get(0.getPostalCode();
字符串knownName=addresses.get(0.getFeatureName();//仅当可用时,否则返回NULL

我假设您希望它出现在带有标记的地图视图上

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    class="com.google.android.gms.maps.MapFragment" />
在你的onCreate中初始化它

mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
然后创建覆盖方法,
onMapReady()

我想这应该是你想要的。如果还需要其他内容,请进行注释。

//添加mapView activity.xml
            //Add mapView  activity.xml
            <com.google.android.maps.MapView
                        android:id="@+id/map_view"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:apiKey="your api key"

                        android:clickable="true"
                        android:layout_below="@id/tv_location" />

        //Add Activity
         // Getting reference to MapView
                mapView = (MapView) findViewById(R.id.map_view);
                googleMap = mapView.getMap();

    final LatLng latLng = new LatLng(lat, lng);
            final MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin));
            final CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(14f).tilt(70).build();
            markerOptions.position(latLng);
 googleMap.addMarker(markerOptions);
//添加活动 //获取对MapView的引用 mapView=(mapView)findViewById(R.id.map\u视图); googleMap=mapView.getMap(); 最终LatLng LatLng=新LatLng(lat,lng); final MarkerOptions MarkerOptions=new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.map_-pin)); final CameraPosition CameraPosition=new CameraPosition.Builder().target(latLng).zoom(14f).tilt(70).build(); 标记选项位置(板条); googleMap.addMarker(markerOptions);
Geocoder coder=新的地理编码器(本);
String locationName=list.get(i);
地理编码器gc=新地理编码器(本);
List addressList=null;
试一试{
addressList=coder.getFromLocationName(locationName,1);
}捕获(IOE异常){
e、 printStackTrace();
}
地址位置=地址列表。获取(0);
双纬度=location.getLatitude();
double longitude=location.getLongitude();
LatLng帮助中心=新LatLng(纬度、经度);
googleMap.addMarker(新标记选项().position(帮助中心)
.title(list.get(i));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(帮助中心,6f));

你是否在安卓系统中使用谷歌地图,如果是,请向我们展示代码,也许我们能帮上忙。。!你可以更具体地说明你需要如何显示确切的位置,比如它在谷歌地图中是作为标记还是不在地图视图中?或者只是细节?格式良好的分步教学。这应该是可以接受的答案。是否有@override方法onMapReady()?非常好的解释,希望我能接受answer@ArnoldBrown
YourClassName在mapreadycallback上实现
在这段代码中,你可以找到任何使用地名的地方。这里的列表是一个列表视图和列表。get(i)是特定的地名
@Override
public void onMapReady(GoogleMap gMap) {
    googleMap = gMap;
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    try {
        googleMap.setMyLocationEnabled(true);
    } catch (SecurityException se) {

    }

    //Edit the following as per you needs
    googleMap.setTrafficEnabled(true);
    googleMap.setIndoorEnabled(true);
    googleMap.setBuildingsEnabled(true);
    googleMap.getUiSettings().setZoomControlsEnabled(true);
    //

    LatLng placeLocation = new LatLng(***YOUR LAT***, ***YOUR LNG***); //Make them global
    Marker placeMarker = googleMap.addMarker(new MarkerOptions().position(placeLocation)
                  .title(***NAME OF PLACE HERE***));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(placeLocation));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 1000, null);
}
            //Add mapView  activity.xml
            <com.google.android.maps.MapView
                        android:id="@+id/map_view"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:apiKey="your api key"

                        android:clickable="true"
                        android:layout_below="@id/tv_location" />

        //Add Activity
         // Getting reference to MapView
                mapView = (MapView) findViewById(R.id.map_view);
                googleMap = mapView.getMap();

    final LatLng latLng = new LatLng(lat, lng);
            final MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin));
            final CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(14f).tilt(70).build();
            markerOptions.position(latLng);
 googleMap.addMarker(markerOptions);
    Geocoder coder = new Geocoder(this);
    String locationName = list.get(i);
    Geocoder gc = new Geocoder(this);
    List<Address> addressList = null;
    try {
        addressList = coder.getFromLocationName(locationName, 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Address location = addressList.get(0);
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    LatLng helpcenter = new LatLng(latitude, longitude);
    googleMap.addMarker(new MarkerOptions().position(helpcenter)
            .title(list.get(i)));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(helpcenter, 6f));