使用google map geolocation api對raspberry pi進行地理定位

下面範例使用了Google Map GeoLocation Api對raspberry pi進行地理定位,
其中key可在https://console.developers.google.com申請,每日免費額度是2500(每100秒限制10000次)

/*
npm i pi-wifi google-geolocation
node main.js
*/
function geolocation(callback){
  var geolocation = require ('google-geolocation') ({
    key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  });
  var piWifi = require('pi-wifi');

  piWifi.scan(function(err, networks) {
    if (err) {
      return console.error(err.message);
    }
    //console.log(networks);

    var items=[];
    for(i in networks){
      items.push({
        'macAddress': networks[i].bssid,
        'signalStrength': networks[i].signalLevel,
      });
    }

    var params={
      wifiAccessPoints: items,
    };

    geolocation (params, (err, data) => {
      if (err) {
        return;
      }

      var result={
        'lat': data.location.lat,
        'lng': data.location.lng,
        'accuracy': data.accuracy,
        'type': 'wifi',
      };

      if(callback &&  typeof(callback) == "function")
        callback(result);
    });
  });
}

geolocation(function(location){
  console.log(location);
  var url ="https://www.google.com.tw/maps/search/"+location.lat+","+location.lng;
  console.log(url);
});

Apache Maven 初體驗

參考網址: http://www.codedata.com.tw/java/understanding-gradle-2-maven/hello-world/
1.建立專案

export maven_group=tw.com.slanla
export maven_id=helloworld
mvn archetype:generate \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false \
  -Dmaven.test.skip=true \
  -DgroupId=${maven_group} -DartifactId=${maven_id}


2.編譯專案

cd $maven_id
mvn package


3.執行程式

java -cp target/${maven_id}-1.0-SNAPSHOT.jar ${maven_group}.App


如果不想要每次執行jar時,還要指定mainclass的話,
可以在pom.xml中加入

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <mainClass>tw.com.slanla.App</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>

如下圖所示:

這樣一來就可以用java -jar直接執行:

java -jar target/${maven_id}-1.0-SNAPSHOT.jar