简体   繁体   中英

Xamarin Forms - Google map show multiple markers on map

I am using Android.Gms.Maps.GoogleMap to display a map in my Xamarin forms app android project. I can't find much documentation on displaying (ideally) a circle on the screen at a particular latitude and longitude, or (less ideally) a marker pin.

Is there a function such as GoogleMap.addMarker(double latitude, double longitude) or similar, to display such a circle or pin?

To add circle on google map use this code:

Circle circle;
public void OnMapReady (GoogleMap googleMap)
  {
    map = googleMap;

    var circleOptions = new CircleOptions ();
    circleOptions.InvokeCenter (new LatLng (lat, lon));
    circleOptions.InvokeRadius (circle.Radius);
    circleOptions.InvokeFillColor (0X66FF0000);
    circleOptions.InvokeStrokeColor (0X66FF0000);
    circleOptions.InvokeStrokeWidth (1);
    circle = map.AddCircle (circleOptions);
  }

To add marker use this:

Marker marker;
public void OnMapReady (GoogleMap googleMap)
{
 MarkerOptions markerOpt1 = new MarkerOptions();
    markerOpt1.SetPosition(new LatLng(lat, lon));
    markerOpt1.SetTitle("testing");
    marker = googleMap.AddMarker(marker1);
}

To avoid multiple marker and circle you can edit their position without making a new one:

 circle.Center = new LatLng(latLng.Latitude, latLng.Longitude);
 marker.Position = new LatLng(latLng.Latitude, latLng.Longitude);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM