Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>J2ME Map Route Provider</h2> <p>maps.google.com has a navigation service which can provide you route information in <a href="http://code.google.com/intl/uk/apis/kml/documentation/" rel="nofollow noreferrer">KML</a> format. </p> <p>To get kml file we need to form url with start and destination locations: </p> <pre><code>public static String getUrl(double fromLat, double fromLon, double toLat, double toLon) {// connect to map web service StringBuffer urlString = new StringBuffer(); urlString.append("http://maps.google.com/maps?f=d&amp;hl=en"); urlString.append("&amp;saddr=");// from urlString.append(Double.toString(fromLat)); urlString.append(","); urlString.append(Double.toString(fromLon)); urlString.append("&amp;daddr=");// to urlString.append(Double.toString(toLat)); urlString.append(","); urlString.append(Double.toString(toLon)); urlString.append("&amp;ie=UTF8&amp;0&amp;om=0&amp;output=kml"); return urlString.toString(); } </code></pre> <p>Next you will need to parse xml (implemented with SAXParser) and fill data structures: </p> <pre><code>public class Point { String mName; String mDescription; String mIconUrl; double mLatitude; double mLongitude; } public class Road { public String mName; public String mDescription; public int mColor; public int mWidth; public double[][] mRoute = new double[][] {}; public Point[] mPoints = new Point[] {}; } </code></pre> <p>Network connection is implemented in different ways on Android and Blackberry, so you will have to first form url:</p> <pre><code> public static String getUrl(double fromLat, double fromLon, double toLat, double toLon) </code></pre> <p>then create connection with this url and get InputStream.<br> Then pass this InputStream and get parsed data structure:</p> <pre><code> public static Road getRoute(InputStream is) </code></pre> <p>Full source code <a href="http://code.google.com/p/j2memaprouteprovider/source/browse/trunk/J2MEMapRouteBlackBerryEx/src/org/ci/geo/route/RoadProvider.java" rel="nofollow noreferrer">RoadProvider.java</a> </p> <h2>BlackBerry</h2> <blockquote class="spoiler"> <p> <a href="http://img94.imageshack.us/img94/4389/bbmaproute.jpg" rel="nofollow noreferrer">Dead link - BlackBerry Storm screenshot</a> </p> </blockquote> <pre><code>class MapPathScreen extends MainScreen { MapControl map; Road mRoad = new Road(); public MapPathScreen() { double fromLat = 49.85, fromLon = 24.016667; double toLat = 50.45, toLon = 30.523333; String url = RoadProvider.getUrl(fromLat, fromLon, toLat, toLon); InputStream is = getConnection(url); mRoad = RoadProvider.getRoute(is); map = new MapControl(); add(new LabelField(mRoad.mName)); add(new LabelField(mRoad.mDescription)); add(map); } protected void onUiEngineAttached(boolean attached) { super.onUiEngineAttached(attached); if (attached) { map.drawPath(mRoad); } } private InputStream getConnection(String url) { HttpConnection urlConnection = null; InputStream is = null; try { urlConnection = (HttpConnection) Connector.open(url); urlConnection.setRequestMethod("GET"); is = urlConnection.openInputStream(); } catch (IOException e) { e.printStackTrace(); } return is; } } </code></pre> <p>See full code on <a href="http://code.google.com/p/j2memaprouteprovider/source/browse/#svn/trunk/J2MEMapRouteBlackBerryEx" rel="nofollow noreferrer">J2MEMapRouteBlackBerryEx</a> on Google Code</p> <h2>Android</h2> <p><img src="https://i.stack.imgur.com/yYv8N.png" alt="Android G1 screenshot"></p> <pre><code>public class MapRouteActivity extends MapActivity { LinearLayout linearLayout; MapView mapView; private Road mRoad; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); new Thread() { @Override public void run() { double fromLat = 49.85, fromLon = 24.016667; double toLat = 50.45, toLon = 30.523333; String url = RoadProvider .getUrl(fromLat, fromLon, toLat, toLon); InputStream is = getConnection(url); mRoad = RoadProvider.getRoute(is); mHandler.sendEmptyMessage(0); } }.start(); } Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { TextView textView = (TextView) findViewById(R.id.description); textView.setText(mRoad.mName + " " + mRoad.mDescription); MapOverlay mapOverlay = new MapOverlay(mRoad, mapView); List&lt;Overlay&gt; listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); mapView.invalidate(); }; }; private InputStream getConnection(String url) { InputStream is = null; try { URLConnection conn = new URL(url).openConnection(); is = conn.getInputStream(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return is; } @Override protected boolean isRouteDisplayed() { return false; } } </code></pre> <p>See full code on <a href="http://code.google.com/p/j2memaprouteprovider/source/browse/#svn/trunk/J2MEMapRouteAndroidEx" rel="nofollow noreferrer">J2MEMapRouteAndroidEx</a> on Google Code</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload