0

Folks, How to create a marker from value of string on Xamarin.iOS Google Maps.

string as icon marker

On Android, I can use code below and I can create a icon with string, but on iOS Xamarin, how do create it?

     IconGenerator icon = new IconGenerator(Context);
     Icon.SetContentRotation(-180); 
     MarkerOptions markerOptions = new MarkerOptions()
          .SetIcon(Android.Gms.Maps.Model.BitmapDescriptorFactory.FromBitmap(icon.MakeIcon("350k")))
          .SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude))
          .Anchor(icon.AnchorU, icon.AnchorV)
          .SetRotation(180); 

     _map.AddMarker(markerOptions);

For example, on Android I instantiate the IconGenerator class and it makes possible to pass a value of string "350k"

But I have no idea to do that with Xamarin iOS project.

Nowhere Man
  • 19,170
  • 9
  • 17
  • 42

1 Answers1

0

Welcome to SO!

If using Google Maps for iOS, there is a way to add a marker from google map official sample.

Here is the swift sample code for reference:

let position = CLLocationCoordinate2D(latitude: 10, longitude: 10)
let marker = GMSMarker(position: position)
marker.title = "Hello World"
marker.map = mapView
Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
  • Thank you for the answer but it not produces a Marker labeled" Hello World", it produces a normal marker on the map. I need to produces a marker labeled from string. – Thiago Henrique Sep 08 '20 at 17:05
  • @ThiagoHenrique Could you share which Nuget package of Google Map used ? I will check that. – Junior Jiang Sep 09 '20 at 05:40
  • I am using google maps 2.3.0. This code above produces a single marker but not but not produces what I want. I'm trying to create a marker from value of string and on Android I can do it using IconGenerator. – Thiago Henrique Sep 09 '20 at 13:58
  • With oficial documentation, it creates only a single marker without text information `var position = new CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127); var london = new Marker() { Position = position }; london.Title = "London"; london.Snippet = "Population: 8,174,100"; london.Map = Control as Google.Maps.MapView;` – Thiago Henrique Sep 09 '20 at 18:18
  • @ThiagoHenrique The `Xamarin.Forms.GoogleMaps` nuget package of Xamarin Forms has the latest version is `3.5.0`. And you can have a look at its sample: https://github.com/amay077/Xamarin.Forms.GoogleMaps whether be helpful to achieve your wants. – Junior Jiang Sep 10 '20 at 06:13