Fixed Marker Pin at the Center of a Map

785 views
Skip to first unread message

Diamond

unread,
Oct 8, 2014, 8:29:54 PM10/8/14
to codenameone...@googlegroups.com
Hi Shai,

I'm trying to achieve Uber and Lyft style of mapping and location, I want a Marker Icon to be fixed at the center of the screen.

I was able to achieve this using MapComponent that uses Google Map Tiles and It works fine, except that it's not fluid like native map.

I replaced the Map Component with a NativeMap, It works fine on Simulator because there it uses OpenStreetMap. And eventually, this map now  turnout be more fluid than the map created with MapComponent on simulator. 

When I tested this on real device the Marker icon Label has vanished and the functionality of panning the map around and pinch to zoom is bumpy,though I'm still able to get the center coordinates which I converted to address. 

Is there a way to put a marker icon at a fix point on the screen and still have a native map just like Uber did? Maybe there's any component that has more power over MapContainer.

Attached is a screenshot of what I've done so far.

Please assist,

Thanks,
Diamond
Uber_Style_Mapping.PNG

Shai Almog

unread,
Oct 8, 2014, 10:02:53 PM10/8/14
to codenameone...@googlegroups.com
Hi,
this is problematic since the native maps use a peer component which is always drawn separately from Codename One rendering process: http://www.codenameone.com/blog/understanding-peer-native-components-why-codename-one-is-so-portable

The solution is to add that functionality into the native maps themselves, I know of at least one individual who added something like that to the native maps ports on iOS/Android to achieve his desired UI.

Diamond

unread,
Oct 9, 2014, 3:09:38 AM10/9/14
to codenameone...@googlegroups.com
I added a MapListener to the google map and called ClearMapLayers and addMarker inside the mapPositionUpdated method.

    It works but the problem is when I pan or zoom the Map, the Marker moved with it and got painted at the center after  pointerRelease.

    The only thing unsatisfactory about this is that, it makes it more difficult for users to know where exactly the marker is going to be placed since there is no real time feedback. 

     Is there any method or combination of methods I can use or override to repaint the Marker at the center as I pan and zoom around? 

     I tried overriding pointerPressed and pointerDragged, they don't seem to be effective. Maybe I was implementing them wrongly.


Thanks,

Shai Almog

unread,
Oct 9, 2014, 9:16:07 AM10/9/14
to codenameone...@googlegroups.com
Currently there is no such method, you will need to change the native code to do this.

Mario Barón

unread,
Oct 9, 2014, 9:21:26 AM10/9/14
to codenameone...@googlegroups.com
Hey guys, 

I was working on this for my app as well but unfortunately had to bring it lower on my priority list due to some bugs and stuff on my app. I more or less had it figured out on Android, basically you have to create an ImageView which will contain the image of your marker and then play a little with the layouts, specifically the LinearLayout. 

Unfortunately as Shai said, it must be done by native code, or at least for it to work with no problems otherwise you'd be getting OutOfMemory problems and stuff. I think I'll be soon looking at this issue once again if not this week the next one but it'd be great that if people find a solution they share it and everyoine can benefit. 

Bharat Proteem Gogoi

unread,
Jun 14, 2020, 1:44:12 AM6/14/20
to CodenameOne Discussions
@Daimond

Did you find the solution for the marker being jumped to the center after releasing it.
Reply all
Reply to author
Forward
0 new messages