string conversion problems - the method is not applicable for the arguments
in
Contributed Library Questions
•
6 months ago
Hi all,
I'm creating a tool to track a weather balloon, but I'm stuck on a pretty basic part: drawing a line.
I have the file of fake GPS info being read to mimic the serial input, and then display the information in a line on the map created by googlemapper. I keep getting this error: "The method line(float, float, float, float) in the type PApplet is not applicable for the arguments (double, double, double, double)" and I know it's because of the doubles not working well with the draw function. How can I convert things so that this works?
The googlemapper library returns a double, but how can I convert this since everything I've tried so far returns "Type mismatch: cannot convert from double to int"
Here is my code:
- BufferedReader reader;
- import googlemapper.*;
- import controlP5.*;
- import guicomponents.*;
- double mapCenterLat = 42.66656;
- double mapCenterLon = -72.4831;
- int zoomLevel =15;
- String mapType = GoogleMapper.MAPTYPE_ROADMAP;
- int mapWidth=640;
- int mapHeight=480;
- String inBuffer;
- Boolean isGPSActive;
- ArrayList<Double> lat ;
- ArrayList<Double> lng ;
- Double newLat;
- Double newLng;
- ControlP5 cp5;
- int zoomSlider=7;
- Slider abc;
- PImage map;
- GoogleMapper gMapper;
- public void setup() {
- //start reading the file with fake info
- reader = createReader("C:/Documents and Settings/DWarren/My Documents/Processing/googlemapper_testing/fakegps.txt");
- //sets the window size to 640x480
- size(640, 480);
- //creates new controls using the P5 Library
- cp5 = new ControlP5(this);
- cp5.addSlider("zoomSlider")
- .setPosition(50, 100)
- .setSize(40, 200)
- .setRange(3, 21)
- .setNumberOfTickMarks(9);
- cp5.addButton("refresh")
- .setValue(0)
- .setPosition(50, 80)
- .setSize(40, 19);
- //sets the zoomlevel
- zoomLevel=zoomSlider;
- //loads the google map
- gMapper = new GoogleMapper(mapCenterLat, mapCenterLon, zoomLevel, mapType, mapWidth, mapHeight);
- //loads it to cache
- map = gMapper.getMap();
- //displays it
- image(map, 0, 0);
- }
- long interval = millis();
- //function to run when refresh button is pressed
- public void refresh(int theValue) {
- println("refreshing map");
- try {
- interval = millis();
- zoomLevel=zoomSlider;
- gMapper = new GoogleMapper(mapCenterLat, mapCenterLon, zoomLevel, mapType, mapWidth, mapHeight);
- map = gMapper.getMap();
- image(map, 0, 0);
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- void draw() {
- try {
- String inBuffer = reader.readLine();
- }
- catch (IOException e) {
- e.printStackTrace();
- inBuffer = null;
- }
- //String inBuffer = myPort.readString();
- println(inBuffer);
- String[] op = inBuffer.split(",");
- //only when we get valid data, split it to get coordinates
- if (op.length==6) {
- newLat = Double.valueOf(op[0]); //get latitude
- newLng = Double.valueOf(op[1]); //get longitude
- lat.add(newLat);
- lng.add(newLng);
- isGPSActive=true;
- }
- for (int i=0; i < lat.size() ; i++)
- {
- double lat1 = gMapper.lat2y(lat.get(i));
- double lng1 = gMapper.lon2x(lng.get(i));
- double lat2 = gMapper.lat2y(lat.get(i+1));
- double lng2 = gMapper.lon2x(lng.get(i+1));
- line(lat1,lng1,lat2,lng2);
- }
- }
1