2013年11月2日星期六

How to get the user's location ?

JAVA How to get user location ? ? ? Like cell phones have GPS positioning can get to put ? Specifically how to get it, to get the user and then a city on the line. Seeking code , seeking help ah !
------ Solution ---------------------------------------- ----
before use, specifically to see this article : http://blog.csdn.net/withiter/article/details/8945890


public class GeoBusiness {
/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.out.println(getLocationByIp("220.181.111.147").getCity());
System.out.println(getLocationByIp("220.181.111.147").getCountryName());
}

public static Location getLocationByIp(String ipaddr) throws IOException {
String sep = System.getProperty("file.separator");
String dir = Play.configuration.getProperty("geoip.datdir");
String dbfile = dir + sep + "GeoLiteCity.dat";
LookupService cl = new LookupService(dbfile,
LookupService.GEOIP_MEMORY_CACHE);
Location location = cl.getLocation(ipaddr);

cl.close();
return location;
}
}

------ For reference only ----------------------------------- ----


I call a good look at that web , it seems relatively simple !

没有评论:

发表评论