2017-04-26 5 views
0

マーカーを使用して現在の位置を取得できますが、マーカーを別の場所に設定できず、マーカーを使用して緯度と経度の値を取得できません。私はトーストメッセージ内の現在位置を取得し、私は、マーカーの位置を変更すると、私は値がテキストに結合するためのマーカーに緯度と経度の値を取得していないことが午前このコードで マップ内のマーカーを使用して異なる場所でlongituteと緯度を取得する方法xamarin.android

public class googlemapsAc : Activity, ILocationListener, IOnMapReadyCallback 
    { 
     GoogleMap _map; 
     LocationManager locManager; 
     TextView loc1, loc2; 
     protected override void OnCreate(Bundle savedInstanceState) 
     { 
      base.OnCreate(savedInstanceState); 

      SetContentView(Resource.Layout.mapsActivity); 
      loc1 = FindViewById<TextView>(Resource.Id.btn_loc); 
      loc1 = FindViewById<TextView>(Resource.Id.btn_loc2); 
      locManager = (LocationManager)GetSystemService(LocationService); 
      locManager.RequestLocationUpdates(LocationManager.GpsProvider, 0,0, this); 
      Location location = locManager.GetLastKnownLocation(LocationManager.GpsProvider); 
      MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map); 
      mapFrag.GetMapAsync(this); 
      if (location != null) 
      { 
       MarkerOptions options = new MarkerOptions(); 
       LatLng lat = new LatLng(location.Latitude, location.Longitude); 
       Toast.MakeText(this,"Current location:\nLatitude: " + location.Latitude+ "\n" + "Longitude: " + location.Longitude,ToastLength.Long).Show(); 
       options.SetPosition(lat); 
       p.AddMarker(options); 
      } 
      else 
      { 

       Toast.MakeText(this, "Cannot fetch current location!",ToastLength.Short).Show(); 
      } 
      locManager.RemoveUpdates(this); 
     } 

     public void OnLocationChanged(Location location) 
     { 

     } 

     public void OnProviderDisabled(string provider) 
     { 
      throw new NotImplementedException(); 
     } 

     public void OnProviderEnabled(string provider) 
     { 
      throw new NotImplementedException(); 
     } 

     public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras) 
     { 
      throw new NotImplementedException(); 
     } 
     protected override void OnResume() 
     { 
      base.OnResume(); 
      locManager.RequestLocationUpdates(LocationManager.GpsProvider, 0,0, this); 
     } 
     protected override void OnPause() 
     { 
      base.OnPause(); 
      locManager.RemoveUpdates(this); 
     } 
     public void OnMapReady(GoogleMap googleMap) 
     { 
      _map = googleMap; 
     } 
    } 
} 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/btn_loc" /> 
<TextView 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/btn_loc2" /> 

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

ビュー。

私はトーストメッセージに現在位置を取得することが可能ですが、私は「didnのマーカーの位置を変更したときに、このコードでのTextView

答えて

0

にバインドする場所のマーカーを使用してLANG値LAT取得で私を助けてください緯度と経度の値をマーカーに取得して、その値をテキストビューにバインドします。

私はあなたがマーカーの場所を変更する方法についてのコードを見ていないが、あなたはこのように、たとえば、あなたのマーカーから直接緯度と経度を取得することができます:

var latitude = marker.Position.Latitude; 
var longitude = marker.Position.Longitude; 
関連する問題