Here you can find the source of urlifyMap(Long nid, double latitude, double longitude)
private static String urlifyMap(Long nid, double latitude, double longitude)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Main { private static String urlifyMap(Long nid, double latitude, double longitude) { String url = "http://mapas.sapo.pt/cmap/cmap.html?sz=640,960&ll=" + latitude + "," + longitude + "&z=16&t=m&mks=" + longitude + "," + latitude + ",0,asd," + "&nid=" + nid; return shortenUrl(url); }/*from ww w .ja v a 2s . c o m*/ private static String shortenUrl(String url) { String shortUrl = ""; try { URLConnection conn = new URL("https://www.googleapis.com/urlshortener/v1/url").openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/json"); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write("{\"longUrl\":\"" + url + "\"}"); wr.flush(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { if (line.indexOf("id") > -1) { //hack shortUrl = line.substring(8, line.length() - 2); break; } } wr.close(); rd.close(); } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return shortUrl; } }