-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image component inside Custom Markers and Callouts in Android #1870
Comments
Tested with:
Result:
As a work around, you can try setting targetSdkVersion to a number no more than 23, then
|
In my case images disappear on marker addition. I'm moving the map and adding only those which fall into the viewport. So they consistently disappear. If I put other elements in the custom view, they are shown. So there's a huge problem with Image rendering. Great investigation anyway. |
I tried to fix this few months ago but failed to succeed, I guess i've done some messy code. My idea was actually to implement here https://github.com/react-community/react-native-maps/blob/master/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapMarker.java#L350 a bitmap caching system (https://developer.android.com/topic/performance/graphics/cache-bitmap.html) which would use the marker key as a key of our cache map, and the Bitmap as a value. Maybe this is a wrong idea, just proposing this if someone has time to try and all that stuff |
Can someone fix this issue ? |
For now use |
@foyarash The problem is not the caching system, the problem is that every time it creates a bitmap of the view, and sometimes it does not happen or I don't know what happens, but it does not draw. |
Yeah that's what I noticed. I actually tried some solution and particularly invalidating the MapView after the image has been loaded, but that didn't work. That's really a weird behavior and I'm curious about what is wrong with this |
Putting the Image into a WebView and did the trick for me |
@michaelhitzker I am facing the same issue in Android. Are you using http image url in WebView ?? can you please share your code ?? |
Image Background not working still |
Everyone seems to be struggling with this issue here. Let me tell you a proper workaround for this. First of all, using WebView is the only proper solution for this right now. Now rather than using webview for your image. you should be having only webview in the callout and create a proper html for your whole callout view and insert it into your webview. For ex:
I know we are all mobile developers here, but writing a quick html is never a big deal, and in CSS too, there is flex box layout system like react native you can take profit of. So change you thought and use html in webview or wait till this is fixed. This way, you can have multiple images in you callout, rendering exactly you wants and in the very first time, every image will show up. In the screenshot below, you can see there are 4 images in one callout and callout in a single webview. |
Could this work even with local images inside webview? |
You have to save your local images somewhere on your server. That's where the solutions start. otherwise, there are ways by which you can show local images in webview too. You have to research that part. |
People, what helped me is adding images inside of Text component. Please notice tree:
|
Hey @nemanjas1, I came across your fix for this issue and it is the only one I have been having any luck with. Although my image is still cut off horizontally though the middle. Any idea why? |
@EvanJMarsh, Can you provide some example of tree @nemanjas1 mention. |
The workaround I've found, but using WebView working on iOs and Android |
Answer of another reply to similar issue, if not the same.
|
I create a pull request , android google map callout support Image. |
It work like a charm. Please merge it! |
Guys, what about ImageBackground? Works fine on iOs but on Android it doesn't render... |
|
for me issue appears only when tracksViewChanges is passed false to resolved try this |
@HoangTrongKhanh bạn ơi, phần này họ vẫn chưa merge à bạn? |
I got it to work with WebView :) I added react-native-webview:
(For older android versions I had to add react-native-get-random-values):
Then, I imported:
at the top of my map page to work in older Android versions. And, in my render() function I added:
I created a view in my server to serve an html page with only that image, and, got it to work. Please notice that All images are loaded from server When map is populated with markers (one request for each image). Hope that helps anybody.... |
Ok I solve it by putting let imageUrl = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg"
.
.
.
<Image
source = {{ uri: imageUrl }}
style = { { width: 100, height: 100 } }
resizeMode = "cover"
/>
<Text style={styles.markerText}>
{ "Company Logo Image" }
<Image
source={{ uri: imageUrl }}
style={{ width: 0, height: 0 }}
resizeMode="cover"
/>
<Text/> |
None of the above workarounds works for me. |
Here is the work around i found that forces a rerender. But now it doesnt work on IOS!
|
I tried many things and finally I found a solution. Worked for me on Android. Just putting Image tag inside a Text tag
|
@sasan-ebrahimi This does not work for me. |
ok finally i got something working. I used @akshaygpta007 method. using webview, html and css. I created a function that took the object that had the image path as a prop. then passed that in
Then i used the above function as demonstrated in the snippet below. You may have to adjust the size and placement of your photo, but it works for me.
Then i just place my custom callout out as follows. I do a platform check because normal images display fine on IOS.
|
Check this answer 2633 |
My issue was that image would not appear if it had any Here's an example of my code. const Marker = (markerInfo) => {
const [loading, setLoading] = React.useState(true);
return (
<MapView.Marker
tracksViewChanges={loading}
coordinate={{
latitude: markerInfo.latitude,
longitude: markerInfo.longitude,
}}
>
<View style={{width: 40, height: 50, alignItems: 'center', justifyContent: 'center'}}>
<Image
onLoad={() => setLoading(false)}
fadeDuration={0}
style={{width: 30, height: 40}}
resizeMode={'contain'}
source={{uri: markerInfo.icon}}
/>
</View>
</MapView.Marker>
);
};
...
<MapView
data={...}
initialRegion={...}
renderMarker={markerInfo => <Marker key={String(markerInfo.id)} {...markerInfo}/>}
/> |
Hopefully, i found a working solution here https://github.com/react-native-maps/react-native-maps/issues/3339#issuecomment-1770843834
|
Image component inside Custom Markers and Callouts in Android not appearing or rendering.
Merging all issues to this.
Please, clone https://github.com/alvelig/react-native-maps-example and try if you can reproduce.
Mention your lib version, react-native version, Android version, and is it a device or emulator.
The text was updated successfully, but these errors were encountered: