I\'m currently developing an app for Android which uses google map service. Because users will be able to see thousands of markers I would like to load only those which are curr
I'm doing something similar to yourself but I'm using a server. The reason I'm doing so is for computational reasons. When the application first starts a HTTP request is sent to a php script which contains a MySQL query. The php script recieves the users current lat / long and gives back in a JSON all points within 1KM of the current location. The application then parses that JSON into a local MySQL database and does stuff with it.
To send the HTTP request and parse the JSON into a database I'm doing the following..
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://URL");
httppost.setEntity(new UrlEncodedFormEntity(parameters));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
//convert response to string
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
new AlertDialog.Builder(this)
.setTitle("Woops!")
.setMessage("Getlocations:It appears the server is not reachable. Check your connectivity and try again.")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
//User wants to start activity..
}
})
.show();
Log.e("log_tag", "Error in connection or convert "+e.toString());
}
//parse json data
try{
System.out.println("parsing data");
JSONArray jArray = new JSONArray(result);
if(icount != 0){
try{
SQLiteDatabase db = tweets.getWritableDatabase();
db.delete(TABLE_NAME,null,null);
}finally {
tweets.close();
}
}
//TODO: Change this to num
for(int i=0;i
For this to work all you need is a short php file which takes the Lat / lng Something like...
That'll take in the values and print results in JSON.
//edit: To get the lat / lng in the first place I'm using the GPS.
Hope this helps.