Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Little confused about a plugin I purchased.
Started by pgyore Oct 10 2019 01:36 PM

- - - - -
9 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

pgyore

[GLOBAL: userInfoPane.html]
pgyore
  • Observer

  • 15 posts
  • Corona SDK

I hope this is in the right forum.

 

I purchased the Corona-SDK-Maps plugin, have attempted to email support, but to no avail.

 

https://github.com/Crno/Corona-SDK-Maps

 

In the documentation, for addMarker(), one of the parameters that is auto-generated for each marker by the addMarker() function is "id", which according to the doc is a number, is not required (and cannot be assigned at the time of creation).

 

https://github.com/Crno/Corona-SDK-Maps/blob/master/addMarker.markdown

 

Once a marker is added and clicked, in the markerListener(event) callback, if I attempt to print this value (event.id) I get:

 

"table: 0x0blahblahblah",

 

...not a number, as expected. However, if I arbitrarily call hideMaker(1) the marker disappears!

 

I would like to use marker.id to do things (ie. if (marker.id == 42) then do something end), since I may have multiple markers, but I don't know what to do with a table, unless I missing something obvious.

 

I hope this makes sense.

 

Thank you in advance.



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,539 posts
  • Enterprise

You will need to reach out to the plugin developer as linked on the Marketplace page: https://marketplace.coronalabs.com/corona-plugins/map-plugin

 

This is a third-party plugin that is supported by the plugin creator.

 

Rob



[TOPIC: post.html]
#3

pgyore

[GLOBAL: userInfoPane.html]
pgyore
  • Observer

  • 15 posts
  • Corona SDK

Yeah, in Line 3, I mentioned plugin support from the author has gone unanswered. I emailed him in August and haven't heard from him ever. So, I thought I would try here.

 

I was hoping I was missing something related to programming, not necessarily this particular plugin.

 

I did send another email, with the above contents.

 

Thanks again.



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

When you need help with code related issues, the first step should be to share your code that demonstrates the issue.

 

I quickly read through the doc page that you posted and it seems that you've just misunderstood how the plugin or tables work in Lua.

 

When you create a marker, you need to pass in a table containing the desired parameters, as described in the docs. You may also, if you so way, add that id parameter and the plugin will use that. If you don't pass an id, then the plugin will probably just pick the next one that is free.

 

This "next free" is most likely just as simple as

marker[#marker+1] = ... some cool code ...

What this code does is "#marker" finds the last or the first empty value in the "marker" table. "#marker+1" then adds a new unique entry to said table.

 

So, if you don't have any markers and you create a new one without passing an id, the new marker's id will naturally be 1, then 2 for the next one, and so on and so forth. Again, you can freely decide to pass in custom ids at any point, as per the documentation.

 

-

When you print out the event target value, you get a table because the plugin creates a Lua table. Now, it seems that the markers are all added to the same table and their id matches their table key, i.e. marker with id 1 is the first entry in the marker table, so if you remove marker[1], you remove marker which has id 1.

 

Without having seen your code or having ever used the plugin, I'm guessing that what you'd want is actually printing out "event.target.id", not "event.id".



[TOPIC: post.html]
#5

pgyore

[GLOBAL: userInfoPane.html]
pgyore
  • Observer

  • 15 posts
  • Corona SDK

First, thank you for reading my post, reading the plugin documentation, and for your reply.

 

 

What I don't understand is why, when queried, marker.id equals a table; not a number, per the documentation. All of the other elements (when printed to console) are what they should be ((number) lat, (number) lon, (string) description, etc). 

 

Also, the plugin does not allow inserting my own id at creation, which would be great. I tested it and it simply does not work as you thought and I hoped. Also, after marker creation, the simple "marker.id = 42", which would be fine, does not work. One must use the included MAP.editMarker(table) function as well as define another completely detailed table, with seven or more of the table elements.

 

Finally, "event.id" is defined in the sample provided by the plugin author, and it prints "table: 0x0000000", not a number, and the reason for this forum post. I tried printing your recommended "event.target.id", which makes sense, and it threw an error.

 

 

Thanks again.



[TOPIC: post.html]
#6

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

The documentation does have several examples where a specific id is passed to a new marker, e.g. in the sample code for removeMarker() (https://github.com/Crno/Corona-SDK-Maps/blob/master/removeMarker.markdown). Having read a bit more of the documentation, it seems that the reason why event.target.id doesn't work is simply because the plugin manages the touch event itself and you just provide it with a listener, see https://github.com/Crno/Corona-SDK-Maps#mainlua.

 

Are you sure you are adding the id in the table, as shown in the sample code? I'm not familiar with your knowledge of Lua, so my questions may seem too basic. If it isn't working as expected, then I'm guessing that the author of the plugin has some updating to do.

 

Most likely, if not definitely, the plugin is creating a Lua table for each new marker. You could, if you so desired, attach certain values to these tables that you could later search for. This documentation page offers a nifty function for finding all contents of a table. You could try using this to see if you can find where and how the markers are added https://docs.coronalabs.com/tutorial/data/outputTable/index.html. Still, this might all be unnecessary if the issue is just that the plugin is not being utilised correctly.



[TOPIC: post.html]
#7

pgyore

[GLOBAL: userInfoPane.html]
pgyore
  • Observer

  • 15 posts
  • Corona SDK

So, I followed the link and I ran printTable(event) inside the markerListener callback, and below is the result:

table: 0x6000031e62c0 {
	[lon] => -118.2437
	[mapID] => 1
	[description] => "myDescription"
	[id] => table: 0x6000031e62c0 {
		[lon] => -118.2437
		[directory] => userdata: 0x10a7f3aa0
		[description] => "myDescription"
		[_functionListeners] => table: 0x6000031d9040 {
			[tap] => table: 0x6000031db900 {
				[1] => function: 0x600000a1c880
			}
		}
		[id] => table: 0x6000031d9040 {
			*table: 0x6000031d9040
		}
		[lat] => 34.0522
		[_proxy] => userdata: 0x600002a33988
		[restoreY] => 466.37362670898
		[onTransition] => true
		[icon] => "marker_idle.png"
		[_class] => table: 0x6000031d9040 {
			[removeEventListener] => function: 0x600002af38a0
			[addEventListener] => function: 0x600002af36c0
			[__index] => table: 0x600003141a40 {
				*table: 0x600003141a40
			}
		}
	}
	[lat] => 34.0522
}

As you can see, the first three elements are num, num, string, as documented. Then we get to "id". According to the documentation, the "id" should be a num, not a table, and in this case, as you can see, the table contains redundant (as well as additional) information about the marker.

 

(The "id" table (which should be a num) even contains the element "id". Another table.)

 

In fact, if I print "event.id.description", I get the string "myDescription", because var "description" is in the "id" table.

 

I will continue to attempt to communicate with the author.

 

Thank you.



[TOPIC: post.html]
#8

john.armstrong

[GLOBAL: userInfoPane.html]
john.armstrong
  • Contributor

  • 136 posts
  • Corona SDK

good luck. I have not received any answers from the author either. The documentation clearly says it returns a number for the id.. not a table!



[TOPIC: post.html]
#9

runislabs

[GLOBAL: userInfoPane.html]
runislabs
  • Observer

  • 7 posts
  • Corona SDK

Fixed the bug. Id somehow was marker's object, not the id object.

If you have any issues leave messages here.

 

Thank you!



[TOPIC: post.html]
#10

pgyore

[GLOBAL: userInfoPane.html]
pgyore
  • Observer

  • 15 posts
  • Corona SDK

Thank you for the update, runislabs.

 

I will do some testing and will leave a message here if I have any issues.

 

Merry Christmas to all.




[topic_controls]
[/topic_controls]