Titanium.Map.Annotation.image not working properly
Hello
There seems to be a problem with the Titanium.Map.Annotation.image property, or the documentation thereof. The documentation states the property is an ImageView, but also a string: documentation
It seems the latter is true, as I am able to display an image file as a pin:
Ti.Map.createAnnotation({
latitude: lat,
longitude: lng,
title: 'test',
image: '/path/to/image.png'
});
but if I reference an ImageView object instead, the annotation doesn't show up.
It would be great if it were possible to use an ImageView object as an annotation image instead, this would offer us much more possibilities.
I tried creating the ImageView I wanted, then saving it to file and referencing that instead. This would work, except that an ImageView combined of multiple ImageView objects looks different when saved to file (ImageView.toBlob()) than on the screen.. but that's another issue.
Any help on this? I've seen the other topics on the pinimage matter, but they seem outdated, as the property was then only available on Android.
2 Answers
-
Accepted Answer
Unfortunately the image property of a map annotation can only be a local path. In a project I extended the Ti sdk for allowing remote urls for image annotations. Enabling the use of proper views would require a similar effort…
-
I've found a way to load a remote image as the custom pin easily. It actually makes sense to do it this way as well. Simply use Kevin Hopkins image caching functions found here:
http://kevin.h-pk-ns.com/2011/03/11/image-views-in-titanium-how-to-deal-with-caching/
Once you import his library, you call the function:
cachedImageView('imageDirectoryName', 'http://MyRemoteServer.com/public/images/1.png', imgMyImage);Replace imgMyImage with the name of your pin and it works great. The cachedImageView just sets the "image" property of whatever resource you pass to it in that 3rd parameter so it doesn't have to be an imageview. It can be an annotation since it uses the same 'image' property name.