简体   繁体   中英

How does the Google Maps for Mobile “My Location” feature work?

I've installed the Google Maps Java 2 ME app on my Nokia N73 which supports the Location API (JSR 179), but does not have an in-built GPS sensor. The "My Location" features works correctly, and is able to pinpoint my position within the city.

When I tried to access the CellID, LAC and other related data, I got nulls. So how is Maps able to calculate my position? Is it because their app is signed with a certificate? (mine isn't)

What it does is measure the signal strength of WiFi, 3G and GSM Base Stations/Access Points in the area. Since all WiFi access points have a unique MAC address, and 3G and GSM Base Stations also have unique identifications, it now knows which base stations you are close to and approximately how close to them you are, based on the strength.

There are now a few ways to find the distance. If it knows where the Access Point/Base Station is, then it can triangulate your position, based on the signal strength. For this to work it needs to have access to at least 3 AP/BS. With GSM it can also use the Timer Advance, which is an estimation of how far away you are from the base station, with an accuracy of approximately 1km. With 3G it's even better.

Another approach (used by Google and others) is that all your signal strength data is sent to a server. If you have a GPS then your GPS info is also sent along. The server can then build a map of signal strengths to different AP/BS at different coordinates. Since you don't have a GPS it now compares the signal strengths you have passed along and tries to find the closest match in its database, and then finds the location at that closest point.

This is easy to do in J2ME using the APIs defined by JSR 179 . There's a simple example here: JavaME Location API Example application with Source Code (that page is broken at the time of writing; here's the Google Cache version ).

That sample works perfectly on my Nokia E63, which like your N97 N73 doesn't have a GPS but does support cell-based positioning. Here's the core of it:

public void checkLocation() throws Exception
{
    String string;
    Location l;
    LocationProvider lp;
    Coordinates c;

    // Set criteria for selecting a location provider:
    // accurate to 500 meters horizontally
    Criteria cr = new Criteria();
    cr.setHorizontalAccuracy(500);

    // Get an instance of the provider
    lp = LocationProvider.getInstance(cr);

    // Request the location, setting a one-minute timeout
    l = lp.getLocation(60);
    c = l.getQualifiedCoordinates();

    if(c != null ) {
      // Use coordinate information
      double lat = c.getLatitude();
      double lon = c.getLongitude();
      string = "\nLatitude : " + lat + "\nLongitude : " + lon;

    } else {
        string ="Location API failed";
    }
    midlet.displayString(string);
}

@Marius is right about how the technology works, but the JSR 179 APIs hide all that detail from you. @JaanusSiim is wrong that you can't do this from J2ME.

Note that the sample application doesn't require signing to work - the phone will pop up a prompt asking whether to allow the unsigned application to access your location information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM