Xamarin-Forms | Android - Reference image in GroundOverlayOptions -


i using android.gms.maps class create custom renderer google map in xamarin forms app, android phones. looking add image map using groundoverlayoptions

    groundoverlayoptions newarkmap = new groundoverlayoptions()     .invokeimage(bitmapdescriptorfactory.fromresource(/*my image?*/))     .position(e.point, 8600f, 6500f);      map.addgroundoverlay(newarkmap); 

i need images resource id in commented section of code. how find out images' resource id? there alternative way it?

using bitmapdescriptorfactory have multiple options available how obtain bitmapdescriptor

  • fromresource
  • fromasset
  • frompath
  • frombitmap

couple of examples:

to use fromresource, image must within resource tree, assumably within drawable subfolder, xamarin generate id descriptor in form of resource.drawable.xxxxx , integer constant:

var overlayoption = new groundoverlayoptions()     .invokeimage(bitmapdescriptorfactory.fromresource(resource.drawable.overlayface2))     .position(e.point, 5000f, 5000f); 

enter image description here

fromasset loads image "assets" subfolder:

var overlayoption = new groundoverlayoptions()     .invokeimage(bitmapdescriptorfactory.fromasset("overlayface.png"))     .position(e.point, 5000f, 5000f); 

enter image description here

frompath loads image arbitrary path, load image downloaded , stored in app's cache directory, or image stored on sdcard, etc...

var overlayoption3 = new groundoverlayoptions()     .invokeimage(bitmapdescriptorfactory.frompath("/mnt/sdcard/download/overlayface.png"))     .position(e.point, 5000f, 5000f); 

note: largest problem people run not setting size of image correctly, in kilometers. not pixels, not miles, etc...

note: speed, keep image sizes in power of 2, otherwise the map library have transform power of 2 image everytime loads overlay (memory , performance hit)


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -