天天看點

GOOGLE地圖基站定位-Google Mobile Maps API

如果你在你的手機裝過Google Mobile Maps,你就可以發現隻要你的手機能連接配接GPRS,即使沒有GPS功能,也能定位到你手機所在的位置, 隻是精度不夠準确。在探讨這個原理之前,我們需要了解一些移動知識,了解什麼是MNC/LAC/Cell ID。

Mobile Network Code(MNC)

 移動網号碼,中國聯通CDMA系統的MNC為03,中國移動的為00。

Mobile Country Code(MCC)

 移動使用者所屬國家代号:460

Location Area Code(LAC)

 地區區域碼,用來劃分區域,一般一個小地方就一個LAC,大地方就...

Cell Tower ID(Cell ID)

CellID代表一個移動基站,如果你有基站資料,查CellID你就可以知道這個基站在哪裡,移動公司或者警察通過這個知道你是在哪個基站範圍打的行動電話。

這些資訊有什麼用呢? 通過這些資訊可以知道你的手機是從哪個國家,區域和哪個基站接入移動網絡的。是以有些防盜手機丢失後,會發一些類 似"MCC:460;MNC:01;LAC:7198:CELLID:24989"内? .js" type="text/javascript"> 1;的短信到你指定号碼就是這個用途,通過這些資訊可以從移動查到你的 被盜手機在哪裡出現過。不過知道了也沒用,中國人口這麼密集,就是在你身邊你也不知道誰是小偷:)

這些資訊從哪裡來呢,一般的手機系統都提供相應的API來擷取這些資訊(Tower Info),比如Window SmartPhone 或Mobile就是通過RIL.dll裡的API來取得,每個手機作業系統不一樣,相關的資訊可以查相關資料。

得到了這些資訊,如果沒有基站資訊表,得到了這些資訊也不知道在哪,因為隻有移動營運商有相關的資訊,除非你是營運商或者警察才能得到這些資訊。是 不是我們就查不到相應的資料呢,當然不是,強大的Google就有,這裡就要提到Google Mobile Maps API,裡面囊括了比較全的基站資訊,中國的也有,就是偏遠地區的有沒有就不知道了。Google Mobile Maps本身就是使用的這些資訊,感興趣可以試一試,沒有GPS子產品也能定位到你手機位置,但精度不大,取決于基站的位置離你多遠。

同樣我們自己也可以開發相應的手機應用來定位,隻要調用Google現成的API(Secret API)"http://www.google.com/glm/mmap“.

首先讀取你自己手機的CellID和LAC。

通過Http連接配接發送Post請求到http://www.google.com/glm/mmap。

傳入CellID和LAC參數,從API傳回基站的經緯度(Latitude/Longitude)。

另外有個可以參考的例子(windows mobile)http://www.codeproject.com/KB/mobile/DeepCast.aspx

   下面是通過j2me擷取手機imei号碼和cellid(基站号)的例子

package jizhan;

import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener;

import javax.microedition.lcdui.Display;

import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.Form;

import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;

public class GetIMEIAndCellId extends MIDlet implements CommandListener {

    private Command exitCommand = new Command("exit", Command.EXIT, 1);

     Form form = new Form("imei and cellid");

     Display display = null;

    public GetIMEIAndCellId() {

         display = Display.getDisplay(this);

     }

    protected void destroyApp(boolean arg0) {

     }

    protected void pauseApp() {

     }

    protected void startApp() throws MIDletStateChangeException {

        //擷取系統資訊

         String info = System.getProperty("microedition.platform");

        //擷取到imei号碼

         String imei = "";

        //cellid

         String cellid = "";

        //lac

         String lac = "";

        // #if polish.vendor==Sony-Ericsson

         imei = System.getProperty("com.sonyericsson.imei");

        //參考 http://forums.sun.com/thread.jspa?threadID=5278668

        //https://developer.sonyericsson.com/message/110949

         cellid = System.getProperty("com.sonyericsson.net.cellid");

        //擷取索愛機子的

         lac = System.getProperty("com.sonyericsson.net.lac");

        // #else if polish.vendor==Nokia

         imei = System.getProperty("phone.imei");

        if (imei == null || "".equals(imei)) {

             imei = System.getProperty("com.nokia.IMEI");

         }

        if (imei == null || "".equals(imei)) {

             imei = System.getProperty("com.nokia.mid.imei");

         }

        //擷取到cellid

        //參考http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME

        // #if polish.group==Series60

         cellid = System.getProperty("com.nokia.mid.cellid");

        // #else if polish.group==Series40

         cellid = System.getProperty("Cell-ID");

        // #endif

        // #else if polish.vendor==Siemens

         imei = System.getProperty("com.siemens.imei");

        // #else if polish.vendor==Motorola

         imei = System.getProperty("com.motorola.IMEI");

        //cellid 參考 http://web.mit.edu/21w.780/www/spring2007/guide/

         cellid = System.getProperty("CellID");

        // #else if polish.vendor==Samsung

         imei = System.getProperty("com.samsung.imei");

        // #endif

        if (imei == null || "".equals(imei)) {

             imei = System.getProperty("IMEI");

         }

        //展示出來

         form.append("platforminfo:" + info);

         form.append("imei:" + imei);

         form.append("cellid:" + cellid);

         form.setCommandListener(this);

         form.addCommand(exitCommand);

         display.setCurrent(form);

     }

    public void commandAction(Command cmd, Displayable item) {

        if (cmd == exitCommand) {

             destroyApp(false);

             notifyDestroyed();

         }

     }

}

需要注意的是,必須是受信任的Midlet才可以取到這些資料。也就是說Midlet必須經過簽名上述代碼才可以工作,否則擷取到的是NULL。。

下面是從别的地方看來的,沒做過測試,供參考。

a) Nokia = System.getProperty("com.nokia.mid.imei");

System.getProperty("com.nokia.IMEI");

System.getProperty("phone.imei");

b) Samsung

System.getProperty("com.samsung.imei");

c) Sony-Ericsson

System.getProperty("com.sonyericsson.imei");

IMSI: IMSI全稱是International Mobile Subscriber Identification Number,移動使用者身份碼。當手機開機後,在接入網絡的過程中有一個注冊登記的過程,系統通過控制信道将經加密算法後的參數組傳送給客戶,手機中的 SIM卡收到參數後,與SIM卡存儲的客戶鑒權參數經同樣算法後對比,結果相同就允許接入,否則為非法客戶,網絡拒絕為此客戶服務。IMSI唯一的标志了 一個SIM卡。

IMEI: IMEI即International Mobile Equipment Identity(國際移動裝置身份)的簡稱,也被稱為串号,它唯一标志了一台移動裝置,比如手機。 IMEI碼一般由15位數字組成,絕大多數的GSM手機隻要按下“*#06#”,IMEI碼就會顯示出來。其格式如下: TAC即Type Approval Code,為裝置型号核準号碼。FAC即Final Assembly Code,為最後裝配号碼。 SNR即Serial Number,為出廠序号。 SP即Spare Number,為備用号碼。

有時候,我們在應用中需要擷取IMSI或者IMEI号用于将應用程式和手機或SIM卡綁在一起。擷取的方式在各不同廠商的各款手機上不盡相同,在motorola RAZR E6   上采用System.getProperty()擷取。相應程式代碼是:

             String imei= System.getProperty("IMEI"); //for E6

             if ( null == imei )

                 imei = System.getProperty("phone.IMEI");

             String imsi = System.getProperty("IMSI"); //for E6

             if ( null == imsi )

                 imei = System.getProperty("phone.IMSI");

             g.drawString("IMEI: "+imei, 10, 50, Graphics.LEFT | Graphics.TOP);

             g.drawString("IMSI: "+imsi, 10, 70, Graphics.LEFT | Graphics.TOP);

參考位址:

 http://blog.csdn.net/phiger/archive/2009/07/22/4371922.aspx

http://hi.baidu.com/lfcomputer/blog/item/0520e0d37a410a3c970a16c1.html

 http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME

 http://www.cnblogs.com/psunny/archive/2009/10/22/1587779.html

 從此學習網 http://www.congci.com/item/218