Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

App That Uses Maps API
Started by yanko_l10 Apr 10 2016 03:50 PM

63 replies to this topic
business maps api uber find my friends
[TOPIC CONTROLS]
Page 1 of 3 1 2 3
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

Hey guys, I've been working on an app for some time now, and I've reached a roadblock at one of the main functionalities of the app.

 

I want my app to be able to locate other users (in real time) on a map, in order to set up meets or simply to see their location, similarly to how Find My Friends ios app does or the taxi app Uber does.

I was wondering if anyone has done anything like this before, or has any idea of how it can be done, and was willing to chat with me about it?

 

Thanks in advance

-YL

 

edit: I don't think I emphasized the part of setting up meetings in a specific location (also forgot to mention users would be able to accept or decline the "meeting") enough, as this is one of the main purposes for the app to use maps.



[TOPIC: post.html]
#2

graham07

[GLOBAL: userInfoPane.html]
graham07
  • Contributor

  • 256 posts
  • Corona SDK

My initial thought would be that you would need to poll for the location periodically, and then post it to an online database by user ID.

Obviously you would have to handle frequency etc to prevent drain, and allow for security so people can't locate strangers positions.



[TOPIC: post.html]
#3

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

[TOPIC: post.html]
#4

Alex@Panc

[GLOBAL: userInfoPane.html]
Alex@Panc
  • Corona Geek

  • 1,729 posts
  • Corona SDK

Are you looking for someone to help with brainstorming and evaluation of Corona being the correct SDK for this app, or are you looking for someone to write actual code for you to use in this app?

 

I ask because if it's the latter, you might be better posting the in "Corona Jobs" section.



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

This is still a pretty broad topic. Generally speaking

 

1. Your app starts up and starts up location services. See: https://docs.coronalabs.com/api/event/location/index.html

2. Upon startup, you won't get a very accurate location because it's getting from cellular or WiFi. It takes a bit to sync up with the GPS satellites in particular inside buildings. Once you get a location you would use a network.request() and post that location to your online database.

3. You would then next do a query of your online database that says get me everyone within X distance. You want your server to process this if possible (assuming you have your own server to write PHP type scripts connecting to your local database). This will minimize data transmission, which is a goal for people on cellular connections. The online script could use some simple math to compute those within your desired range and return a table of data (JSON encoded) that has all the user info you need and their lat, long.

4. Using the map from the Business App sample where it puts pins on the map for StarBucks locations, you simply use the table of people and add pins using the lat, long included in the table. You can put some information in the speech bubbles that show up. You can then setup a touch handler to goto another page to show more details, setup what you want and so on.

 

Rob



[TOPIC: post.html]
#6

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

@Alex, Neither, I guess. I wanted to try to find someone whos worked on an app similar to this to ask some questions, like what backend they are using and that sort of thing.

 

@Rob Miracle, Since you mention a server, I was wondering if you knew of any particular server service that you would recommend, now that Parse Server is shutting down. I was originally using just a free webhosting server with mysql and php scripts, but then you mentioned something about push notifications in another topic which I dont think that server can do.

Using this method you mentioned, it would (from what I understood) just post one location, once, upon app startup. What if I wanted the location to be updated in real time, would this still be a viable method? My original thoughts were it would be too demandnig on the server and app, which would be constantly running network requests updating the database every X amount of seconds... Am I correct to think this? Is this why the other time (in a different topic) you suggested push notifications (I honestly dont know that much about push notifications other then used for sending messages to your users)?



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

Our currently recommended choice now is Coronium.io. Currently Coronium is being adapted to become Corona Cloud. Today, you have to self-host this. @Develephant provides two hosting options for simple installs. One is Amazon AWS. This is a pay as you use resources service, but you are cloud hosted. The other option is Digital Ocean which is a fixed per month fee.

 

The nice thing about Coronium is I think you have more power on the server side to do custom things like only find people withing a certain distance like you do. Parse was pretty much a data store and you were more limited on the server side scripting

 

As far as push notifications go, any old hosting with PHP can send automated push notifications. There was an old blog post that covered how to setup PHP to send push's. Also there are several other push services out there. Big guys like Urban Airship and Pushwoosh have API's to allow software to generate the messages and they send them but its not free. A popular choice for Corona Developers is to use OneSignal (see: https://documentation.onesignal.com/docs/corona-sdk-overview ).

 

Sending location updates as fast as you get GPS events would be too much. You could probably get away with updating once per minute. People don't move that fast usually.



[TOPIC: post.html]
#8

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

Pardon my ignorance, but using Coronium, what scripting language would I use? Or does it depend on the host, say for example AWS, would it be php?

 

And regarding another one of the functionalities of my app, how would I go implementing user to user contact? Say once i have the maps and location down, a user would want to send a request to another user that is nearby, is this done by user sends request to specific person to server - server sends push notification to receiving user - user agrees or declines - response is sent back to server - server sends push notification to first user with the response? Does this make sense or am i looking at this the wrong way?



[TOPIC: post.html]
#9

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

Coronium uses Lua as it's scripting language!!!!  Check it out: http://coronium.io/

 

Contacting other users would best be done via push notifications. Coronium can do your push notifications for you too. It can handle your login tracking. You're on the right track with your thinking.



[TOPIC: post.html]
#11

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

After some time setting up coronium and aws... I finally got it set up and running and was able to stfp to the server (i was having some troubles with the key pairs).

Do you have any prior experience with coronium? I ask you because i now have to migrate from my old server, and I honestly dont know if my php scripts will need any changes to work with coronium (i know its silly to ask this because how would you know without even seeing my php files)... I hope most of the changes will be in the client side... guess i wont be using network.request anymore



[TOPIC: post.html]
#12

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

I don't want to sound mean, but the question above has nothing to do with "App that uses maps API". It's now a question about Coronium. There is a specific forum for those questions that's monitored by the Coronium creator @develphant. I only have a minuscule amount of experience with Coronium, basically enough to know its feature set.

 

So basically by asking here, the people who can answer your question will never see it. I would start a new question in the Coronium forum.

 

Thanks

Rob



[TOPIC: post.html]
#13

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

Hey Rob,

 

You mentioned a blog post about php push notifications, I went on to look for it but the only one I could find was a post about "Easy APNS" which apparently is only for ios push notifications? Was this the one you meant?

 

edit: I was also going to ask you another thing on how to actually use push notifications to implement the functionality I wanted, but I figured you'd tell me to start a new topic. So here is a link to the new topic, in case you were willing to help me out:

 

https://forums.coronalabs.com/topic/62715-user-to-user-interaction-using-push-notifications/



[TOPIC: post.html]
#14

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

Yes, that's the post.



[TOPIC: post.html]
#15

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

https://gyazo.com/77e16b4db3ad7fadf405717f8c4422bf

 

any ideas why this might be?

 

EDIT: forgot to mention, my map shows up as a grey box in the screen, but it never loads.

 

its initially set to center on current location from mymap.getuserlocation, then i have a text field thats supposed to center on what you search, also add a marker (like in the sample app)



[TOPIC: post.html]
#16

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

figured you'd ask to see my code, so here it is:

local composer = require "composer" 
local scene = composer.newScene()
local widget = require "widget"

-- name all local variables here
-- defined local (scene) functions here

local titleBar, navBar, myMap, addressBar
local attempts = 0

local function maplocationHandler( event )

    local currentLocation = myMap:getUserLocation()

    if ( currentLocation.errorCode or ( currentLocation.latitude == 0 and currentLocation.longitude == 0 ) ) then
        attempts = attempts + 1

        if ( attempts > 10 ) then
            native.showAlert( "No GPS Signal", "Can't sync with GPS.", { "Okay" } )
        else
            timer.performWithDelay( 1000, locationHandler )
        end
    else
        myMap:setCenter( currentLocation.latitude, currentLocation.longitude )
        myMap:setRegion( currentLocation.latitude, currentLocation.longitude )
		local options = { 
			title="You are here",   
		}
        myMap:addMarker( currentLocation.latitude, currentLocation.longitude, options )
    end
end


local function mapSearchLocationHandler(event)
	if ( event.isError ) then
        print( "Map Error: " .. event.errorMessage )
    else
		myMap:setCenter( event.latitude, event.longitude, false )
		myMap:setRegion( event.latitude, event.longitude, 0.25, 0.25, false)
		local options = { 
			title=event.text,   
		}
		myMap:addMarker( event.latitude, event.longitude, options )
	end
end

local function addressBarHandler( event )
    if event.phase == "began" then

    elseif event.phase == "ended" or event.phase == "submitted" then
        myMap:requestLocation( event.target.text, mapSearchLocationHandlerLocationHandler )
        native.setKeyboardFocus( nil )
    elseif event.phase == "editing" then
        print( event.newCharacters )
        print( event.oldText )
        print( event.startPosition )
        print( event.text )
    end
end

function scene:create( event )
   local sceneGroup = self.view
   --your code here; define display objects, sprites, physics bodies, etc - but don't play any sounds or animations yet.
	navBar = widget.newNavigationBar({
        title = "Set Appointment Location",
        backgroundColor = { 0,0,0},
        titleColor = {1, 1, 1},
    })
	
	sceneGroup:insert(navBar)
	
end

function scene:show( event )
   local sceneGroup = self.view
   local phase = event.phase
   
   if ( phase == "will" ) then
      -- any code placed here will run when the scene is still "off-screen", but about to be displayed to the user. In many cases, this will be empty.
   elseif ( phase == "did" ) then
      -- any code placed here will run as soon as the scene is displayed on screen. This is where you would start any animations, start playing background audio, start timers, etc.
		addressBar = native.newTextField(display.contentCenterX, navBar.y + 90, display.contentCenterX * 1.8, 30)
		addressBar:addEventListener("userInput", addressBarHandler)
		sceneGroup:insert(addressBar)
		
		myMap = native.newMapView(0, 0,display.contentWidth , display.contentHeight + 50) 
		if myMap then
			myMap.mapType = "standard"
			myMap.x = display.contentCenterX
			myMap.y = addressBar.y + 20
			maplocationHandler()
		else
			native.showAlert( "Simulator", "Maps are only avaiable on device.", { "Okay" } )
		end
	end
end

function scene:hide( event )
   local sceneGroup = self.view
   local phase = event.phase
   
   if ( phase == "will" ) then
      -- any code placed here will run when the scene is still on screen, but is about to go off screen. This is where you would stop timers, audio, and animations that you created in the show event.
  elseif ( phase == "did" ) then
      -- any code placed here will run as soon as the scene is no longer visible. In many cases, this will be empty.
		addressBar:removeSelf()
		addressBar = nil
		if myMap and myMap.removeSelf then
			myMap:removeSelf()
			myMap = nil
		end
   end
end

function scene:destroy( event )
   local sceneGroup = self.view
   -- any code placed here will run as the scene is being removed. Remove display objects, set variables to nil, etc.
end

scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )


return scene


[TOPIC: post.html]
#17

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

Are you getting the gray screen in the sim or on device?

If on device, what's going on in your console log?

 

Rob



[TOPIC: post.html]
#18

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

on the device! how do i get to the console log on an android device?



[TOPIC: post.html]
#19

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

[TOPIC: post.html]
#20

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

I'm gonna have to find a new device for this. This one is my friend's phone and it is really old and the touch screen decides to randomly stop working, so i'll get back to you really soon once I get the debugging stuff set up and ill let you know what it says.

 

Thanks!



[TOPIC: post.html]
#21

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

Hey Rob,

 

Installed my app on another android phone today and everything was working fine on it, except for the getUserLocation function which I know I can easily fix, but thanks for the help! I'll be posting again if I get stuck with something else.



[TOPIC: post.html]
#22

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

Hey Rob,

 

Its been a while, been taking breaks on my project because college. Just had a question regarding storing location in a myql database. I don't know if you've done any of this before in one of your projects or simply messing around, but, I'm not entirely sure what the best way of storing location in a database is, taking into consideration I would like to do some simple(?) arithmetic on locations to determine distance from x location to y location. From what I read online, some people recommended using spatial point datatype in mysql, but some people think it's kind of limiting. Other people suggested storing lat and long as a floating point (10,6). For now, i'm using the latter.

Do you have any advice?

 

Thanks in advance,

YL



[TOPIC: post.html]
#23

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

I'd store the lat and long as floats. If you need the spatial data type (I didn't know there was one), then use it too. It won't hurt to have both and you may find at times you need lat, long for somethings and the other datapoint for others.

 

Rob



[TOPIC: post.html]
#24

yanko_l10

[GLOBAL: userInfoPane.html]
yanko_l10
  • Enthusiast

  • 81 posts
  • Corona SDK

Hey Rob,

 

I took a break from my project, but now I'm back on track. I am currently working on a feature of my app that gets the current location of the user and does a network request to run a php script that finds other people in the database that are in a 25 mile radius of the sent location. I haven't worked with php in a bit, but i was able to get the script to successfully find nearby users, but only through an html form, not the app. I haven't tried to use the script with the app yet because I know (or at least i think i know) that using:

while ($row = mysqli_fetch_assoc($result))

to loop through the results of the query (as I doing am now) wont return the right information to the app, only the last row of the query, I believe. Any tips on how i could return a table/array of the resullts of the query to the app as the network response? Probably with a JSON table or something like that?

 

Thank you in advance!



[TOPIC: post.html]
#25

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,244 posts
  • Enterprise

How are you doing your query?

 

I would also setup another array perhaps something like:

$items = array();
$i  = 0;
while( $row = mysqli_fetch_assoc($result) ) {
    $items[ $i++ ] = $row;
end
echo( json_encode( $items ) );

(untested code)

 

Rob




[topic_controls]
Page 1 of 3 1 2 3
 
[/topic_controls]