如何在地图上使用标记在不同位置使用纬度和纬度xamarin.android

问题描述:

我能够使用标记获取当前位置,但无法将标记设置到不同位置并使用标记获取经度和纬度值。如何在地图上使用标记在不同位置使用纬度和纬度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> 
在此代码,我能够得到敬酒消息的当前位置,但是当我改变标记的位置,我没有得到纬度和经度值入标记绑定,价值观文本

视图。

请帮我用位置标记绑定到TextView的

在此代码,我能够得到敬酒消息当前位置越来越纬度郎值,但是当我改变标记的位置我没有” t将纬度和经度值输入标记以将该值绑定到文本视图。

我没有看到你如何更改标记的位置的任何代码,但你可以直接从您的标记获得的经度和纬度,例如像这样:

var latitude = marker.Position.Latitude; 
var longitude = marker.Position.Longitude;