Geo location and table

Hi,

I’m new to Corona.  I’m trying to pass latitude and longitude on start up then fetch json data(m_id,m_name, distance) from a remote server and put into a table. It’s working ok simulator but it has 3 problems

  1. in the device table widget has empty row at the end of the last row… if i scroll down it goes for ever.

what can I do so so it has same numbe row of json data count? Why it’s work fine in simulator but not in the device

2)  In the device looks like network request is going every few seconds and activity indicator keeps refresh and spin - looks like every thing refresh .

  1. I added button to  request json data again… the button is not triggering anything .

    local widget = require “widget” local json=require"json" local socket = require( “socket” ) local myList = nil local listRecs={} local top=display.statusBarHeight local tableView=nil --display data in a table local function onRowRender( event ) local phase = event.phase local row = event.row local id=row.index or 0 local rowTitle = display.newText( row, listRecs[row.index].m_name, 0, 0, nil, 14 ) rowTitle:setReferencePoint( display.CenterLeftReferencePoint ) rowTitle.x = 15 rowTitle.y = row.contentHeight * 0.3 rowTitle:setTextColor( 0, 0, 0 ) local km = display.newText( row, 'Distance: '…listRecs[row.index].distance…‘km’, 0, 0, nil, 12 ) km:setReferencePoint( display.CenterLeftReferencePoint ) km.x = 15 km.y = rowTitle.y + row.contentHeight * 0.4 km:setTextColor( 0, 0, 0 ) end local function onRowUpdate( event ) local phase = event.phase local row = event.row print( row.index, “: is now onscreen” ) end – which row touched ? local function onRowTouch( event ) local phase = event.phase if ( “press” == phase ) then print( “Touched row:”, event.target.index ) end end – Setting up background and table local function setup() local bg=display.newRect(0,top,display.contentWidth,display.contentHeight-top) bg:setFillColor(0,155,73) tableView = widget.newTableView { left = 0, top = top+50, width = 320, height = 300, maskFile = “images/mask.png”, listener = tableViewListener, onRowRender = onRowRender, onRowUpdate = onRowUpdate, onRowTouch = onRowTouch, maxVelocity = 1.0, friction = 0.972, noLines = false, } end – process jason data local function processJson(event) listRecs=json.decode(event.response) for x=1, #listRecs do tableView:insertRow { isCategory = false, rowHeight = 50, rowColor = { default={ 255, 255, 255 }, over={ 0, 175, 250 } }, lineColor = { 150, 150, 150, 50 }, } native.setActivityIndicator(false) end end – pass GEO data request json data local function showRecords() local locationHandler = function( event ) – Check for error (user may have turned off Location Services) --print(‘h’) if event.errorCode then native.showAlert( “GPS Location Error”, event.errorMessage, {“OK”} ) print( "Location error: " … tostring( event.errorMessage ) ) native.showAlert(‘GPS location failed’) else native.setActivityIndicator(true) local lat = string.format( ‘%.4f’, event.latitude ) local lng = string.format( ‘%.4f’, event.longitude) local URL=‘http://www.test.com/index.php?lat=’..lat..’&lng=’…lng network.request(URL,‘GET’,processJson) end end – Activate location listener Runtime:addEventListener( “location”, locationHandler ) end setup() showRecords() local function updateGeo() showRecords() end – create refresh button local btnRefresh=widget.newButton{ left=200, top=30, height=10, width=100, id=“button1”, label=“Refresh”, event=updateGeo }