Here it is, probably not optimized for efficiency, cleanliness, and some
portions of code probably aren't used at all anymore. But! in case it might
help anyone, here it is! :)
package ioio.examples.hello;
import java.io.*;
import java.text.DecimalFormat;
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.Uart;
import ioio.lib.api.Uart.Parity;
import ioio.lib.api.Uart.StopBits;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.ZoomControls;
import javax.script.*;
public class MainNew extends IOIOActivity {
public Uart uart4GPS;
OutputStream uart4GPSOutput;
InputStream uart4GPSInput;
String line;
boolean logo = true;
private static TextView rawGPSReadout;
private static TextView rawraw;
String rawGPSReadoutString ="", rawrawString = "";
int runs = 0, currentZoom = 20;
String testOutputString = "";
ImageView gmaps;
ZoomControls zoom;
ProgressDialog pd;
String Longitude, Latitude, mapString;
DecimalFormat df = new DecimalFormat("###.#####");
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pictureswap);
rawGPSReadout = ((TextView)findViewById(R.id.rawGPSReadout));
rawraw = ((TextView)findViewById(R.id.rawraw));
zoom = (ZoomControls) findViewById(R.id.zoomControls1);
zoom.setOnZoomInClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
currentZoom += 5;
new
DownloadImageTask(gmaps).execute("https://maps.googleapis.com/maps/api/staticmap?center="
+ Latitude + "%20,%20" + Longitude + "&zoom=" + currentZoom
+"&size=700x500&sensor=false");
}
});
zoom.setOnZoomOutClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
currentZoom -= 5;
new
DownloadImageTask(gmaps).execute("https://maps.googleapis.com/maps/api/staticmap?center="
+ Latitude + "%20,%20" + Longitude + "&zoom=" + currentZoom
+"&size=700x500&sensor=false");
}
});
/* *** Experimental Copied Code: *** */
pd = new ProgressDialog(this);
pd.setMessage("Downloading Image");
gmaps = (ImageView) findViewById(R.id.googleMapsView);
Button b1 = (Button) findViewById(R.id.mapButton);
b1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new
DownloadImageTask(gmaps).execute("https://maps.googleapis.com/maps/api/staticmap?center="
+ Latitude + "%20,%20" + Longitude + "&zoom=" + currentZoom
+"&size=700x500&sensor=false");
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
findViewById(R.id.marker).setVisibility(View.VISIBLE);
//new
DownloadImageTask(gmaps).execute("https://maps.googleapis.com/maps/api/staticmap?center=38%C2%B048'01.8%22N%20,%2077%C2%B018'32.3%22W&zoom=20&size=700x500&sensor=false");
}
});
}
class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd.show();
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
pd.dismiss();
bmImage.setImageBitmap(result);
}
}
/* *** End Experimental Copied Code: *** */
class Looper extends BaseIOIOLooper {
@Override
protected void setup() throws ConnectionLostException {
uart4GPS = ioio_.openUart(40, 39, 57600, Parity.NONE, StopBits.ONE);
}
public void loop() throws ConnectionLostException {
if(runs < 1){
try{
uart4GPSInput = uart4GPS.getInputStream();
BufferedReader rd = new BufferedReader(new
InputStreamReader(uart4GPSInput));
do{
line = rd.readLine();
}while(!line.substring(0,6).equals("$GPGGA"));
rd.close();
String [] words = line.split("\\,");
Thread.sleep(1000);
for (int i =0; i < words.length; i++) testOutputString += ("\t" + words[i]);
Thread.sleep(1000);
setRawText(testOutputString);
setText("Latitude: " + getLatitude(line) + "\nLongitude: " +
getLongitude(line) + "\nNumber of Satilites: " + words[7] + "\nHorizontal
Dilution of Prescision:" + words[8] + " - Fair");
}catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
uart4GPS.close();
}
}
}
public String getLongitude(String NMEAsentence) throws
InterruptedException{
String [] words = NMEAsentence.split("\\,");
Thread.sleep(1000);
String longitudeValue = words[4];
String longitudeDirection = words[5];
Thread.sleep(1000);
String longitude = longitudeValue.substring(0,3) + "°" +
longitudeValue.substring(3, 5) + "'" +
df.format((Double.parseDouble((longitudeValue.substring(6))) * 0.006))
+"\"" + longitudeDirection;
Longitude = longitudeValue.substring(0,3) + "%C2%B0" +
longitudeValue.substring(3, 5) + "'" +
df.format((Double.parseDouble((longitudeValue.substring(6)))* 0.006))
+"%22" + longitudeDirection;
//if (longitudeDirection.equals("W")) longitude = "-" + longitude;
return longitude;
}
public String getLatitude(String NMEAsentence) throws InterruptedException{
String [] words = NMEAsentence.split("\\,");
Thread.sleep(1000);
String latitudeValue = words[2];
String latitudeDirection = words[3];
Thread.sleep(1000);
String latitude = latitudeValue.substring(0,2) + "°" +
latitudeValue.substring(2, 4) + "'" +
df.format((Double.parseDouble((latitudeValue.substring(5))) * 0.006)) +"\""
+ latitudeDirection;
Latitude = latitudeValue.substring(0,2) + "%C2%B0" +
latitudeValue.substring(2, 4) + "'" +
df.format((Double.parseDouble((latitudeValue.substring(5))) * 0.006))
+"%22" + latitudeDirection;
//if (latitudeDirection.equals("S")) latitude = "-" + latitude;
return latitude;
}
public double minutes2Decimal(double minutes){
return (minutes / 60);
}
@Override
protected IOIOLooper createIOIOLooper() {return new Looper();}
public void setText(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
rawGPSReadoutString = str;
rawGPSReadout.setText(rawGPSReadoutString);
runs++;
}
});
}
public void setRawText(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
rawrawString = str;
rawraw.setText(rawrawString);
runs++;
}
});
}
public void launchMapView (View view){
Intent intent = new Intent(this, MainNew.class);
startActivity(intent);
}
}
On Tuesday, April 1, 2014 10:17:26 PM UTC-4, Brad E wrote:
>
> Same! Realize this thread is now pretty stale but I'm doing the very same
> and plan on using *this*.
> <https://joinup.ec.europa.eu/svn/gvsig-mobile/pilots/branches/libLocation/src/org/gvsig/location/nmea/NmeaSentenceDecoder.java>(Hope
>
> I'm not wrong in assuming TinyGPS sends its coordinates in NMAE sentences,
> although, I am quite confident I saw $GPS...... headings in the raw output
> I saw from it earlier.)
>
> I'd be happy to share my code, as an android/ioio adaptation, once I'm
> done.
>
> On Tuesday, July 12, 2011 5:32:18 AM UTC-4, Henrique wrote:
>>
>>
>> Agreed! We would really appreciate it.
>>
>> Thanks.
>>
>> On Jul 11, 5:52 pm, Ytai Ben-Tsvi <[email protected]> wrote:
>> > WOW, Great!
>> > If you would be so kind to share your code once done, I'm guessing
>> others
>> > would appreciate it.
>> >
>> > Either way, good luck.
>> >
>> > Ytai
>
>
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.