I am working on an app which will provide route for the student shuttle. I successfully built this app which will show route map along with stops. I now like开发者_开发知识库 to add new functionality which will show the location of student shuttle in real time. When student looks at the shuttle route, they should also see a moveining icon on the map which is the real time location of the shuttle. ANy idea how this can be done ...???
Thanks in advance
Well first you have to deal with GPS and how to use it in you application, for that purpose stackoverflow.com has some answers already: What is the simplest and most robust way to get the user's current location in Android?
Then your have to deal with the google maps api in order to display the icons and to do geo coding: using-google-maps-android
Update:
public class JsonDownloader{
private static final String URI = "http://mySite.net/rest/getData.php";
@SuppressWarnings("unchecked")
public static String receiveData(){
String result = "";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(url);
HttpResponse res = null;
try {
res = client.execute(method);
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
InputStream is = res.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
return result;
}
}
This code would make a basic http request and return the any data that is returned by your php script as string. This is useful for just downloading gps data without posting anything.
For storing gps data you need the same class, you could modify the class above to perform both post and get requests. So first you need to specify the post parameters. So we can add just the method postData: http://www.androidsnippets.org/snippets/36/index.html
All this has to happen in a async way because it's a time consuming operation, for details have a look at the code in the comments: http://android-projects.de/2010/08/13/threading-in-android-apps/
精彩评论