Getting correct result from database using counter
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Getting correct result from database using counter
I can't work out for sure what is going on, but one thing I can see is in your addMarker handler you are expecting two parameters. The pPosition is constructed from the latitude and longitude, separated by comma. I wonder if something is fooling the addMarker handler into believing that there are three parameters, and trying to use just the lat as the position and the long as the title.
Also in loadSelectedResult you add 1 to counter, but not the tCounter variable
Also in loadSelectedResult you add 1 to counter, but not the tCounter variable
-
- Posts: 40
- Joined: Sat Oct 24, 2015 5:42 pm
Re: Getting correct result from database using counter
Hi SparkOut!
Thanks for taking a look. The addMarker handler is doing its job...it is putting the correct values into latitude, longitude, and title (using pPosition and pTitle). Additionally, I changed to "add 1 to tCounter" in "loadSelectedResult" and that did not change the results I am getting.
I continue to think the trouble is in the "getMarkerCode" function, specifically in where the "add 1 to tCounter" and "end repeat" is placed. I changed my database (now "databaseGetMarkerCode") just to make it unique from the other database that gets the address and lat/long in the "loadSelectedResult" handler in the card script. Below is from my google maps api substack.
function getMarkerCode pName
if sMarkers[pName] is empty then
return "error: no such marker."
else
local tMarkerCode, tPlaceJson, tPlaceArray
put databaseGetMarkerCode() into tData ## each line of tData contains the zIndex numerical value. There are 3 lines.
put empty into tLocArray
put 1 into tCounter
set the itemDel to tab
repeat for each line tLine in tData
put item 1 of tLine into tLocArray[tCounter]["zIndex"]
put "var " & pName & " = new google.maps.Marker({" & CR into tMarkerCode
put "icon: 'https://chart.googleapis.com/chart?chst ... tter&chld= " & tLocArray[tCounter]["zIndex"] & "|FE6256|000000|'," & CR after tMarkerCode
put "position: new google.maps.LatLng(" & sMarkers[pName]["pos"] & ")," & CR after tMarkerCode
put "map: map," & CR after tMarkerCode
put "title:'" & sMarkers[pName]["title"] & "'," & CR after tMarkerCode
put "});"& CR after tMarkerCode
put getPlaceByLatLong(sMarkers[pName]["pos"]) into tPlaceJson
put jsonToArray(tPlaceJson) into tPlaceArray
##put tPlaceArray["results"][1]["formatted_address"]
put "(function (marker) {"&CR after tMarkerCode
put "google.maps.event.addListener(marker, 'click', function (e) {"&CR after tMarkerCode
put "infobox.setContent('<div id=" & quote & "infobox" & quote & " >'+'<p>'+" & quote & tPlaceArray["results"][1]["formatted_address"] "e & "+'</p>'+'</div>');" & CR after tMarkerCode
put "infobox.open(map, marker);"&CR after tMarkerCode
put "markCentered(marker.position);"&CR after tMarkerCode
put "});" & CR after tMarkerCode
put "})(" & pName & ");"&CR after tMarkerCode
add 1 to tCounter
end repeat
end if
return tMarkerCode
end getMarkerCode
I currently have 3 records or lines in my database. Depending on where the "add 1 to tCounter" and "end repeat" lines are located, I get 1 of 2 results...
Result A -- only the results from line 1 of the record is being used...therefore tLocArray[1]["zIndex"] appears in all 3 of the markers. OR
Result B -- only the results from line 3 of the record is being used...therefore tLocArray[3]["zIndex"] appears in all 3 of the markers.
I may have to add more "if/then" statements to get it to work.
Thanks for taking a look. The addMarker handler is doing its job...it is putting the correct values into latitude, longitude, and title (using pPosition and pTitle). Additionally, I changed to "add 1 to tCounter" in "loadSelectedResult" and that did not change the results I am getting.
I continue to think the trouble is in the "getMarkerCode" function, specifically in where the "add 1 to tCounter" and "end repeat" is placed. I changed my database (now "databaseGetMarkerCode") just to make it unique from the other database that gets the address and lat/long in the "loadSelectedResult" handler in the card script. Below is from my google maps api substack.
function getMarkerCode pName
if sMarkers[pName] is empty then
return "error: no such marker."
else
local tMarkerCode, tPlaceJson, tPlaceArray
put databaseGetMarkerCode() into tData ## each line of tData contains the zIndex numerical value. There are 3 lines.
put empty into tLocArray
put 1 into tCounter
set the itemDel to tab
repeat for each line tLine in tData
put item 1 of tLine into tLocArray[tCounter]["zIndex"]
put "var " & pName & " = new google.maps.Marker({" & CR into tMarkerCode
put "icon: 'https://chart.googleapis.com/chart?chst ... tter&chld= " & tLocArray[tCounter]["zIndex"] & "|FE6256|000000|'," & CR after tMarkerCode
put "position: new google.maps.LatLng(" & sMarkers[pName]["pos"] & ")," & CR after tMarkerCode
put "map: map," & CR after tMarkerCode
put "title:'" & sMarkers[pName]["title"] & "'," & CR after tMarkerCode
put "});"& CR after tMarkerCode
put getPlaceByLatLong(sMarkers[pName]["pos"]) into tPlaceJson
put jsonToArray(tPlaceJson) into tPlaceArray
##put tPlaceArray["results"][1]["formatted_address"]
put "(function (marker) {"&CR after tMarkerCode
put "google.maps.event.addListener(marker, 'click', function (e) {"&CR after tMarkerCode
put "infobox.setContent('<div id=" & quote & "infobox" & quote & " >'+'<p>'+" & quote & tPlaceArray["results"][1]["formatted_address"] "e & "+'</p>'+'</div>');" & CR after tMarkerCode
put "infobox.open(map, marker);"&CR after tMarkerCode
put "markCentered(marker.position);"&CR after tMarkerCode
put "});" & CR after tMarkerCode
put "})(" & pName & ");"&CR after tMarkerCode
add 1 to tCounter
end repeat
end if
return tMarkerCode
end getMarkerCode
I currently have 3 records or lines in my database. Depending on where the "add 1 to tCounter" and "end repeat" lines are located, I get 1 of 2 results...
Result A -- only the results from line 1 of the record is being used...therefore tLocArray[1]["zIndex"] appears in all 3 of the markers. OR
Result B -- only the results from line 3 of the record is being used...therefore tLocArray[3]["zIndex"] appears in all 3 of the markers.
I may have to add more "if/then" statements to get it to work.
Re: Getting correct result from database using counter
Did you change your SELECT statement? The one you posted had zindex as the 4th item in each data line, not the first.
I can't spot anything wrong with your repeat loop and where you increment the counter, very strange. I'd be willing to take a look at this if you are able to send me your stack, database, and other necessary files to pete@lcsql.com.
Pete
I can't spot anything wrong with your repeat loop and where you increment the counter, very strange. I'd be willing to take a look at this if you are able to send me your stack, database, and other necessary files to pete@lcsql.com.
Pete
-
- Posts: 40
- Joined: Sat Oct 24, 2015 5:42 pm
Re: Getting correct result from database using counter
Hi Pete!
I did change the SELECT statement. That part is working correctly.
I will send you everything to the email you provided. I very much appreciate you taking a look!
I did change the SELECT statement. That part is working correctly.
I will send you everything to the email you provided. I very much appreciate you taking a look!
Re: Getting correct result from database using counter
Hi,
just to be sure:
Or do you use:with a wrong rowDelim?
I make such mistakes all the time ...
Have fun!
just to be sure:
Do you really have proper lines in tData?Bellballer1 wrote: repeat for each line tLine in tData
Or do you use:
Code: Select all
revDataFromQuery([columnDelim],[rowDelim],databaseID,SQLQuery[,varsList])
I make such mistakes all the time ...
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
-
- Posts: 40
- Joined: Sat Oct 24, 2015 5:42 pm
Re: Getting correct result from database using counter
Hi AxWald!
I do have the proper lines in tData. I continuously check that tData contains the proper lines.
I appreciate you taking a look!
Really, all I'm trying to do is get different numbers into the markers on my map. For example, I want the 1st marker to be labeled "6", the 2nd marker should have a label of "4" and so on. I just want the markers to have different labels.
I do have the proper lines in tData. I continuously check that tData contains the proper lines.
I appreciate you taking a look!
Really, all I'm trying to do is get different numbers into the markers on my map. For example, I want the 1st marker to be labeled "6", the 2nd marker should have a label of "4" and so on. I just want the markers to have different labels.