how to display near friends?

cirollo

Active Member
Licensed User
Longtime User
Hi!

a customer ask me for an app that will show all the members of a social network in the nearby.

the idea is to show a google map with some markers on it, depending from the radius of the area on the display (of course, if i zoom out, the markers will increase....), if I click on the marker, the user profile will appear...

something like "near" application of new sony psvita.

the problem is that I don't know how to set up, I'm thinking of sending, as a user, my position to a remote server and store it in a table (using a service or widget for example) and then, reading all the records from this table and add the markers.

any hint or example to suggest?
 

warwound

Expert
Licensed User
Longtime User
Once you have a database with some users in it you'll want to query it for users nearest to each other's location.

You can find a code example here that you should be able to adapt to your needs.

(Scroll down to 'Finding Locations with MySQL').

Martin.
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Ok, but....

See the MySQL tutorial. Each device needs to send its coordinates to the online database. You should then query for the friends based on your current position.

Dear Erel, I'm stuck in connection between B4A and mysql. I've done the following:

- created a mysql db on my hosting provider via php myadmin
- set up a table called countries and inserted 3 records inside from php myadmin
- made the php script starting from your example and changing only the first lines
like this:
B4X:
<?php

$databasehost = "localhost";
$databasename = "emmeci_near";
$databaseusername ="test_estasi";
$databasepassword = "1234";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input"); 
$sth = mysql_query($query);

if (mysql_errno()) { 
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysql_error(); 
}
else
{
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
    }
    print json_encode($rows);
}
?>

- uploaded the php script with filezilla client to the http directory of my site
- downloaded your mysql project and changed only the address like this:

B4X:
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
   Dim req As HttpRequest
   'req.InitializePost2("http://www.b4x.com/android/countries.php", Query.GetBytes("UTF8"))
   req.InitializePost2("http://www.emmecisistemi.com/countries.php", Query.GetBytes("UTF8"))
   hc.Execute(req, TaskId)
End Sub

but no records are showed, if I try from browser get \nQuery was empty error (and is correct)!!!


what's wrong????
 
Last edited:
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
????

If i compile in debug mode, In the log tab, after connecting to the device, I cannot see any error message, only events regarding the installation and start of the app

by the way, I think that the server is responding correctly but is the query passed to the web service that is empty????
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
the log command is present

I attach a photo to explain better

sorry but I'm using xp on a macbook and I don't know how to make print screen ;-)
 

Attachments

  • IMG_20121009_172951.jpg
    IMG_20121009_172951.jpg
    89.9 KB · Views: 211
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
the server....

I suppose the server is reached in this way:

req.InitializePost2("http://www.emmecisistemi.com/countries.php", Query.GetBytes("UTF8"))

or I'm wrong????
If I access that URL from a browser I get the query is empty message, so the webservice I suppose is working
 
Upvote 0
Top