Community of MapPoint and Bing Maps Users and Developers
This is a discussion on How to Retrive location name form latitude and Longitude in J2ME? within the Development forums, part of the MapPoint Desktop Discussion category; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; 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.lcdui.StringItem; import javax.microedition.location.*; import javax.microedition.location.Coordinates; ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| How to Retrive location name form latitude and Longitude in J2ME? import javax.microedition.lcdui.*; 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.lcdui.StringItem; import javax.microedition.location.*; import javax.microedition.location.Coordinates; import javax.microedition.location.Criteria; import javax.microedition.location.Location; import javax.microedition.location.LocationException; import javax.microedition.location.LocationProvider; import javax.microedition.midlet.MIDlet; import java.util.*; public class LocSearch extends MIDlet implements CommandListener { private Display display; private Form form; private Command exitCommand; private Command refreshCommand; private StringItem text; public String str; // private LandmarkImpl landmark = null; private Location location; private LocationProvider locationProvider; private Coordinates coordinates; private Criteria criteria; public Alert alert; private Timer tm; // private Object reversegeocoder; //<editor-fold defaultstate="collapsed" desc=" Generated Fields "> //</editor-fold> /** * The LocSearch constructor. */ public LocSearch() { form = new Form("Finding location."); tm = new Timer(); exitCommand = new Command("Exit", Command.EXIT, 2); refreshCommand = new Command("Refresh", Command.OK, 1); text = new StringItem("Your position:", "\nPress \"Refresh\""); form.append(text); form.addCommand(exitCommand); form.addCommand(refreshCommand); form.setCommandListener(this); display = Display.getDisplay(this); display.setCurrent(form); // Set criteria for selecting a location provider: // accurate to 500 meters horizontally criteria = new Criteria(); criteria.setHorizontalAccuracy(500); try { // Get an instance of the provider locationProvider = LocationProvider.getInstance(criteria); } catch (LocationException e) { return; } if (locationProvider == null ) { text.setText("Location API failed."); form.removeCommand(refreshCommand); } } private void initialize() { } public void startMIDlet() { String string; string = "Calculating position..."; text.setText(string); // while(!exitCommand) { try{ tm.wait(9000); checkLocation(); }catch (Exception e) { return; } } } public void resumeMIDlet() { // write pre-action user code here // write post-action user code here } public void switchDisplayable(Alert alert, Displayable nextDisplayable) { // write pre-switch user code here Display display = getDisplay(); if (alert == null) { display.setCurrent(nextDisplayable); } else { display.setCurrent(alert, nextDisplayable); } // write post-switch user code here } //</editor-fold> private void checkLocation() { String string; try { // Request the location, setting a one-minute timeout location = locationProvider.getLocation(100); } catch (LocationException e) { return; } catch (InterruptedException e) { return; } coordinates = location.getQualifiedCoordinates(); if (coordinates != null) { // Use coordinate information double lat = coordinates.getLatitude(); double lon = coordinates.getLongitude(); string = "\nLatitude : " + lat + "\nLongitude : " + lon; location.getAddressInfo(); } else { string = "Calculating position, no fix yet."; } text.setText(string); } public Display getDisplay () { return Display.getDisplay(this); } public void exitMIDlet() { switchDisplayable (null, null); destroyApp(true); notifyDestroyed(); } public void startApp() { checkLocation(); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { if (c == refreshCommand) { checkLocation(); } else if (c == exitCommand) { notifyDestroyed(); } } } |
| |||
| Re: How to Retrive location name form latitude and Longitude in J2ME?
Hi, GetLocation returns a Location object. But the name will then be the latitude / longitude pair. FindAddressResults returns a collection of location objects. Also is ObjectsFromPoint. The Locations can be street addresses, postcodes, points of interest or other.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz www.comfortsoftware.be MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
![]() |
| Tags |
| form, j2me, latitude, location, longitude, retrive |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find Location Name through Longitude Latitude | Anonymous | MapPoint Desktop Discussion | 5 | 02-17-2010 04:24 AM |
| How to get latitude and longitude | ma2005pp | MapPoint Desktop Discussion | 3 | 09-28-2005 01:57 AM |
| Latitude and Longitude | virgilar | MapPoint Desktop Discussion | 1 | 03-21-2005 01:01 PM |
| From Location to Latitude Longitude | Anonymous | MapPoint Desktop Discussion | 1 | 01-29-2004 01:45 PM |
| NMEA latitude/longitude and mappoint latitude/longitude | muurman | MapPoint Desktop Discussion | 3 | 11-22-2003 04:42 AM |