【问题标题】:Showing map in Processing and displaying Tweets based on their Lat and Lon coordinates?在处理中显示地图并根据其纬度和经度坐标显示推文?
【发布时间】:2013-06-20 06:21:29
【问题描述】:

有人可以帮我在 Processing 上显示世界地图,然后在相应位置绘制推文吗?

【问题讨论】:

  • 这是个大问题。您有首选的方法吗?大概你想把它放在一个网页中?在这种情况下,我会推荐 D3.js,d3js.org
  • 如果不是用于网络,twitter4j.orgunfoldingmaps.org 可以很方便。我已经用这个工具做到了。
  • @bbill D3 是一个很好的推荐,但 Fari 说他们不想使用 Processing...

标签: twitter processing


【解决方案1】:

这不是一个完整的答案,但应该显示如何在世界地图上绘制位置。请注意执行笛卡尔坐标的 getPoint() 方法(您可以对 Processing 中的 map() 函数执行相同的操作。还请注意,构造函数会进行计算以将您使用的地球图像调整为草图窗口的大小...

WorldMap world;
Point[] cities = new Point[6];

void setup() {
  size(800, 480);
  background(255);
  stroke(0);
  strokeWeight(1.5);
  ellipseMode(CENTER);
  smooth();

  // World
  world = new WorldMap(0, 0, width, height);

  // Cities
  cities[0] = world.getPoint(45.24, -75.43);  // Ottawa
  cities[1] = world.getPoint(38.53, -77.02);  // Washington
  cities[2] = world.getPoint(51.32, 0.50);    // London
  cities[3] = world.getPoint(48.48, 2.20);    // Paris
  cities[4] = world.getPoint(39.55, 116.25);  // Beijing
  cities[5] = world.getPoint(35.40, 139.45);  // Tokyo

}

void draw() {

  world.drawBackground();

  for (int i = 0; i < cities.length; i++) {
    ellipse(cities[i].x, cities[i].y, 10, 10);
  }

}

//-------------------------------

class WorldMap {

  int x, y, w, h;
  PImage raster;

   WorldMap(int x, int y, int w, int h) {
     // Scale Image
     if (h >= w/2) {
       this.w = w;
       this.h = w/2;
       this.x = x;
       this.y = (h - this.h)/2;
     } 
     else {
       this.h = h;
       this.w = 2*h;
       this.x = (w - this.w)/2;
       this.y = y;
     }

     // Load Image
     raster = loadImage("world_longlatwgs3.png");
  }

 void drawBackground() {
   image(raster, x, y, w, h);
  }

 Point getPoint(float phi, float lambda) {
   Point pt = new Point(x + ((180 + lambda) / 360) * w, y + h - ((90 + phi) / 180) * h);
   return pt;
  }

}

//-------------------------------

class Point extends Point2D {
  Point(float x, float y) { 
    super(x, y); 
  }
}

class Point2D {
  float x, y;
  Point2D(float x, float y) {
    this.x = x; this.y = y;
  }
}

【讨论】:

  • @Fari 如果有帮助,请考虑接受或赞成这个答案 - 如果你解决了这个问题,请发布你自己的答案!承认他人的工作对于让人们在未来回答您的问题大有帮助!
猜你喜欢
  • 2012-11-29
  • 1970-01-01
  • 2011-10-31
  • 2014-01-07
  • 1970-01-01
  • 1970-01-01
  • 2016-03-08
  • 1970-01-01
  • 2014-04-13
相关资源
最近更新 更多