1

In my sketch I want to type a City in a textfield and insert this Information into my API-URL:

var Stadt='Berlin';

function setup() {
   createCanvas(500,500);
   textfield = createInput ();
   textfield.changed(newText);
   loadJSON('https://api.openrouteservice.org/geocode/search?'+
       'api_key=5b3ce3597851110001cf6248a7e197414b934680bff4449c39f000cc'+
       '&text='+Stadt+'', gotData);
}

function newText (){
   console.log (textfield.value());
}

function gotData(data) {
   var city = data.features; 
   var lon = city[0].geometry.coordinates[0];
   var lat = city[0].geometry.coordinates[1];  
   fill(0)
   noStroke();
   ellipse (lat+100, lon+100, 10, 10);

}

I can use textfield.value() to load the information into my sketch, but how can i now change var Stadt to the textfieldvalue()?

foliran
  • 75
  • 6

1 Answers1

1

Are you just looking to do this?

function newText (){
   Stadt = textfield.value();
}

After you make this change, you probably want to call the loadJSON() function again.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • Yes, I tried this before but it wouldn't work - of course. You are totally right I needed to move the JSON. Thanks – foliran Nov 10 '18 at 13:13
  • Another Question: right now i need to click into the textfield to write. Is there a way to automatically select the textfiled? To edit the HTML file would be an option I guess – foliran Nov 10 '18 at 13:18
  • @foliran Sounds like you're looking for **focus**. Please post follow-up questions in their own posts- though, so they're easier to answer. – Kevin Workman Nov 10 '18 at 16:27