# Geolocation and Osc Message

**URL:** https://discourse.processing.org/t/geolocation-and-osc-message/1117
**Category:** Coding Questions
**Created:** [June 20, 2018, 10:27am UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117 "2018-06-20T10:27:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)
#### Post date: [June 20, 2018, 10:27am UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/1 "2018-06-20T10:27:24Z")

</div>

Hello,

i try to create a programm in Java which sends geolocation( longitude, latitude) from Android to PC via oscP5 library. Based on AccelerometerData example i made this code but my problem is that when i run the code in Java Mode on PC and then pushing a button on my phone’s App to send my longitude and my latitude, they appeared in the Console down pn the window of the Programm…My target is to make them appeared in the interface Window of Java Mode after i run it…Just the example…

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [June 21, 2018, 2:19am UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/2 "2018-06-21T02:19:13Z")

</div>

Please share the code that you have.

Kf

---

<div class="post-metadata">

### Author: ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)
#### Post date: [June 21, 2018, 7:59am UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/3 "2018-06-21T07:59:45Z")

</div>

This is the code in Java mode that i run in the PC…I 've got the outpout in the console but not in the interface window that appears after i run the code…

```auto
import ketai.net.*;
import ketai.sensors.*;
import ketai.ui.*;

import oscP5.*;
import netP5.*;
  

OscP5 oscP5;
NetAddress remoteLocation;

double longitude, latitude, altitude;
KetaiLocation location;

void setup() {
 size(1000,600);
orientation(LANDSCAPE);
textAlign(CENTER, CENTER);
textSize(50);

oscP5 = new OscP5(this,12000);
remoteLocation = new NetAddress("192.168.1.2",12000);
}

void draw() {
  background(155);  
    text("Latitude: " + latitude + "\n" + 
      "Longitude: " + longitude + "\n" + 
      "Altitude: " + altitude, -300, -100, width, height);  

  }

void oscEvent(OscMessage theOscMessage) {
 
 
  if (theOscMessage.checkTypetag("fff")) // 6
  {
    latitude = theOscMessage.get(0).floatValue(); // 7
    longitude = theOscMessage.get(1).floatValue();
    altitude = theOscMessage.get(2).floatValue();
  }
  
}
void onLocationEvent(float _latitude, float _longitude, float _altitude)
{
  longitude = _longitude;
  latitude = _latitude;
  altitude = _altitude;
 println("lat/lon/alt: " + latitude + "/" + longitude + "/" + altitude);
}

```

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [June 22, 2018, 12:32am UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/4 "2018-06-22T00:32:43Z")

</div>

> [@netphysicist](#):
>
> text("Latitude: " + latitude + “\n” + "Longitude: " + longitude + “\n” + "Altitude: " + altitude, -300, -100, width, height);

You have already set the textAlign to CENTER, CENTER. It would be easy (and it should work) to have

```auto
text("Latitude: " + latitude + "\n" + 
      "Longitude: " + longitude + "\n" + 
      "Altitude: " + altitude, width/2, height/2);

```

By the way, why are you using negative numbers in your text function? You are taking into account surface area that is not shown in your sketch.

Kf

---

<div class="post-metadata">

### Author: ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)
#### Post date: [June 24, 2018, 7:52am UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/5 "2018-06-24T07:52:51Z")

</div>

i use negative numbers because the text did not show up in the interface for a reason…Anyway now it appears in the window display after i run the code but with zero values in the longtitude,latitude and altitude but i dont know why. In my andoid app they are appeared correct but in the PC (Java mode) it gets zero values.

---

<div class="post-metadata">

### Author: ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)
#### Post date: [June 26, 2018, 6:28pm UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/6 "2018-06-26T18:28:37Z")

</div>

As you can see in the picture bellow in the console there are the longtitude, latitude but in the window after running the code there are zero values.

 ![Message](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/5293e3a271c7e863b0001acb1dba3056c933bc8d.png)

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [June 26, 2018, 8:29pm UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/7 "2018-06-26T20:29:26Z")

</div>

> [@netphysicist](#):
>
> println("lat/lon/alt: " + latitude + “/” + longitude + “/” + altitude);

Put the line above also in the `oscEvent()`. Are you using this code for both your Android and your PC?

Kf

---

<div class="post-metadata">

### Author: ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)
#### Post date: [June 27, 2018, 2:14pm UTC](https://discourse.processing.org/t/geolocation-and-osc-message/1117/8 "2018-06-27T14:14:12Z")

</div>

Still the same problem… Yes i run this code both in my Android and my PC.
