capacitor-community / google-maps

Capacitor Plugin using native Google Maps SDK for Android and iOS.
https://capacitor-community.github.io/google-maps/
MIT License
153 stars 64 forks source link

Marker icon not changing #201

Closed IbrahimElkhatib closed 1 year ago

IbrahimElkhatib commented 1 year ago

Describe the bug I am trying to add a marker with a custom icon from the assets folder, I tried to set the url with: "assets/images/icons/location-pin.png", "../../assets/images/icons/location-pin.png", and "public/assets/images/icons/location-pin.png" with no luck.

To Reproduce Steps to reproduce the behavior:

CapacitorGoogleMaps.addMarker({
          mapId: result.googleMap.mapId,
          position: {
            latitude: this.nearestReader.latitude,
            longitude: this.nearestReader.longitude
          },
          preferences: {
            icon: {
              size: { width: 24, height: 33 },
              url: 'assets/images/icons/location-pin.png',
            },
            snippet: this.nearestReader.readerDescription
          }
        });

Expected behavior The marker icon should change to the custom icon instead of the default marker.

Additional context

Error from Xcode debugger console: Task <60ED9F6B-1DAF-4912-813E-2C658DF00898>.<1> finished with error [-1002] Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=assets/images/icons/location-pin.png, NSErrorFailingURLKey=assets/images/icons/location-pin.png, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <60ED9F6B-1DAF-4912-813E-2C658DF00898>.<1>" ), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <60ED9F6B-1DAF-4912-813E-2C658DF00898>.<1>, NSUnderlyingError=0x6000029c36c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}}

LeleuOficial commented 1 year ago

I believe this will solve your problem: CapacitorGoogleMaps.addMarker({ coordinate: { latitude: this.nearestReader.latitude, longitude: this.nearestReader.longitude }, iconUrl: 'assets/images/icons/location-pin.png', });

tafelnl commented 1 year ago

The icon.url should be an actual URL. You provided it with a relative path, which doesn't work unfortunately.