2017-01-13 14 views
-3

私はアンドロイドアプリケーション内の場所の場所を表示する方法を探しています。私はMySQLデータベース内に格納されている場所の経度と緯度の座標を持っています。今度は、それらを取得して(緯度と経度)、アプリケーションの正確な位置を表示したいと思います。緯度と経度を使用した場所の詳細を取得するには感謝アンドロイドアプリで場所の場所を表示する方法

+0

あなたがAndroid搭載のGoogleマップを使用している場合は、私たちのコードを表示して、私たちが助けてくれるかもしれません..! – W4R10CK

+0

もっと具体的にすることができますどのように正確な場所を表示する必要がありますようにマーカとしてGoogleマップにあるかどうか – vishnumm93

+0

あなたはマップビューでそれをしたいですか?それとも詳細だけ? –

答えて

2

は、以下のコード

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 
1

を使用してください私はあなたがマーカーでマップビュー上でそれをすると仮定しています。

<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    class="com.google.android.gms.maps.MapFragment" /> 

これはあなたにあなたが地図になりたい活動のXMLファイルを追加する必要があります 次に、あなたの活動に、

GoogleMap googleMap; 
MapFragment mapFragment; 

あなたにこれを初期化するのonCreate。

mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); 
mapFragment.getMapAsync(this); 

、その後、オーバーライドメソッドを作成するには、

@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); 
} 

onMapReady()は、私はそれが何をしたいあなたを与えるべきだと思います。あなたが他に何か必要があればコメントする。

+0

適切な形式のステップ・ツー・ステップ命令。これは受け入れられた答えでなければなりません。 –

0
  //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); 
関連する問題