利用Geolocation API 实现map 定位

实现资料:Geolocation API Network Protocol

实现代码:

package com.pokercity.test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class HttpTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	private final static String json = "{\n" + "\"version\": \"1.1.0\",\n"
			+ "\"host\": \"maps.google.com\",\n"
			+ "\"access_token\": \"2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe\",\n"
			+ "\"home_mobile_country_code\": 310,\n"
			+ "\"home_mobile_network_code\": 410,\n"
			+ "\"radio_type\": \"gsm\",\n" + "\"carrier\": \"Vodafone\",\n"
			+ "\"request_address\": true,\n"
			+ "\"address_language\": \"en_GB\",\n" + "\"location\": {\n"
			+ "\"latitude\": 51.0,\n" + "\"longitude\": -0.1\n" + "},\n"
			+ "\"cell_towers\": [\n" + "{\n" + "\"cell_id\": 42,\n"
			+ "\"location_area_code\": 415,\n"
			+ "\"mobile_country_code\": 310,\n"
			+ "\"mobile_network_code\": 410,\n" + "\"age\": 0,\n"
			+ "\"signal_strength\": -60,\n" + "\"timing_advance\": 5555\n"
			+ "},\n" + "{\n" + "\"cell_id\": 88,\n"
			+ "\"location_area_code\": 415,\n"
			+ "\"mobile_country_code\": 310,\n"
			+ "\"mobile_network_code\": 580,\n" + "\"age\": 0,\n"
			+ "\"signal_strength\": -70,\n" + "\"timing_advance\": 7777\n"
			+ "}\n" + "],\n" + "\"wifi_towers\": [\n" + "  {\n"
			+ "    \"mac_address\": \"01-23-45-67-89-ab\",\n"
			+ "    \"signal_strength\": 8,\n" + "   \"age\": 0\n" + " },\n"
			+ "  {\n" + "   \"mac_address\": \"01-23-45-67-89-ac\",\n"
			+ "    \"signal_strength\": 4,\n" + "   \"age\": 0\n" + "  }\n"
			+ " ]\n" + "}";

	public static void main(String[] args) throws IOException {
		URL url = null;
		byte[] postData = json.getBytes();
		InputStream in = null;
		OutputStream out = null;
		try {
			url = new URL("http://www.google.com/loc/json");
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setRequestProperty("HOST", "www.google.com");
		connection.setRequestProperty("Accept", "image/gif,image/x-xbitmap,"
				+ "application/json,*/*");
		connection.setRequestProperty("Content-Type", "application/json");
		connection.setRequestProperty("Content-Length", "" + postData.length);
		connection.setDoOutput(true);
		out = connection.getOutputStream();
		out.write(postData);
		in = connection.getInputStream();
		int c;
		while ((c = in.read()) != -1) {
			System.out.print((char) c);
		}

	}

}

 

基础的东西还是最重要的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值