Use the google Navigation app in my own app

Put your problem here if it does not fit any of the other categories.

Re: Use the google Navigation app in my own app

Postby Chri » Mon Jan 16, 2012 1:28 pm

Would be a possibility.

thx for that
Experienced Developer
Experienced Developer
Posts: 51
Joined: Mon Aug 31, 2009 12:08 pm


Re: Use the google Navigation app in my own app

Postby Chri » Thu Feb 16, 2012 10:24 am

To finish this question:

The following is referring to the android version 3.2:

There is no way to implement an other application into your own (like google navigation)!
And from my point of view (after two months of trying) is implementing a own navigation on google maps (with google maps direction api) not a very good solution, because there come up a lot of bugs (after long long coding :) ) if you do that.
So I would not realize a navigation on google maps.

hope that helps somebody
wkr Chris
Experienced Developer
Experienced Developer
Posts: 51
Joined: Mon Aug 31, 2009 12:08 pm

Re: Use the google Navigation app in my own app

Postby Phyll » Thu Feb 16, 2012 10:18 pm

Hi Chris,

Hadn't heard from you for a while. Guess you should have checked back with me.

Here is what I had done on that:

Code: Select all
package com.bandpsoftware.mapper;
* Google Maps Tutorial
* Txt2Java pCode Generated File
* Version
* B&P Software 2012
* This requires the Google API (Android 2.1)
* The mapping requires the correct API key in main.xml (B&P's won't work for other compilers)
* Uses the direction service to draw a blue line between the endpoints of the direction steps
* Stores the written directions also

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;


public class Mapper extends MapActivity  {
    MapView mapView;
    MapController mc;
    GeoPoint p;
    ArrayList<Direction> directions = new ArrayList<Direction>();
    Direction dir = null;

    public void onCreate(Bundle icicle) {

        mapView = (MapView) findViewById(;
        mapView.setBuiltInZoomControls(true); //newer one

        // This sets up where to show a push pin
        String coordinates[] = {"42.35849","-71.06010"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);
        p = new GeoPoint(
            (int) (lat * 1E6),
            (int) (lng * 1E6));
        // This gets everything going


    protected boolean isRouteDisplayed() {
        return true;

    // This moves the map center to point p
    public void goToPoint() {
        int cx = (int) (((directions.get(0).lat+directions.get(directions.size()-1).lat)/2d)*1E6);
       int cy = (int) (((directions.get(0).lng+directions.get(directions.size()-1).lng)/2d)*1E6);
       GeoPoint gp = new GeoPoint(cx,cy);
       int latSpan = (int) (Math.abs(directions.get(0).lat-directions.get(directions.size()-1).lat)*1E6);
       int lngSpan = (int) (Math.abs(directions.get(0).lng-directions.get(directions.size()-1).lng)*1E6);
        mc = mapView.getController();
        mc.zoomToSpan(latSpan, lngSpan);

    // This shows the pushpin at point p
    public void showPosition() {
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();

    class MapOverlay extends Overlay {

        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
            super.draw(canvas, mapView, shadow);
            Paint paint = new Paint();
            Point screenPts = new Point();
            GeoPoint gp;
            int i = 0;
            float lx = 0;
            float ly = 0;
            while (i<directions.size()) {
                dir = directions.get(i);
                gp = new GeoPoint((int) ( * 1E6), (int) (dir.lng * 1E6));
                mapView.getProjection().toPixels(gp, screenPts);
                if (i > 0) canvas.drawLine(lx, ly, screenPts.x, screenPts.y, paint);
               lx = screenPts.x;
               ly = screenPts.y;               
                }//drawing route
            mapView.getProjection().toPixels(p, screenPts);

            // This puts the marker on the map
            Bitmap bmp = BitmapFactory.decodeResource(
                getResources(), R.drawable.pushpin);
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-46, null);
            return true;

        public boolean onTouchEvent(MotionEvent event, MapView mapView)
            // Touch event
            // When the map is pressed and released the pushpin goes
            // to that point
            if (event.getAction() == 1) {
                p = mapView.getProjection().fromPixels(
                    (int) event.getX(),
                    (int) event.getY());
            return false;

        }//mapoverlay class

    public void getDirections(String loginUrl) {
       JSONObject jArray = null;
       String result = "";
       String s;
       String s1;
       String s2;
           HttpGet request = new HttpGet(loginUrl);
           HttpClient httpClient = new DefaultHttpClient();
           HttpResponse response = httpClient.execute(request);
           HttpEntity entityResponse = response.getEntity();
           result = EntityUtils.toString(entityResponse);
            } catch(Exception e) {
               Log.e("log_tag", "Error converting result "+e.toString());
        try {    
            jArray = new JSONObject(result);
          } catch(JSONException e) {
                Log.e("log_tag", "Error parsing data "+e.toString());
        try {
           JSONArray array = jArray.getJSONArray("routes");
           JSONObject routes = array.getJSONObject(0);
           JSONArray legs = routes.getJSONArray("legs");
           JSONObject steps = legs.getJSONObject(0);
            JSONArray legs1 = steps.getJSONArray("steps");
              for(int i = 0; i < legs1.length(); i++){
                  JSONObject steps1 = legs1.getJSONObject(i);
                  if (i == 0) s = steps1.getString("start_location");
                      else s = steps1.getString("end_location");
                  s1 = s.substring(s.indexOf(":")+1);                    //cut off beginning
                  s = s1.substring(s1.indexOf(":")+1, s1.indexOf("}"));  //isolate longitude
                  s1 = s1.substring(0, s1.indexOf(","));                 //isolate latitude
                  s.replaceAll(" ", "");                                 //remove spaces
                  s1.replaceAll(" ", "");
                  s2 = steps1.getString("html_instructions");
                  dir = new Direction(Double.parseDouble(s),Double.parseDouble(s1),s2);
            } catch(Exception e) {
                Log.e("log_tag", "Error converting result "+e.toString());


    public class Direction {
        public double lng = 0;
        public double lat = 0;
       public String txt = "";
       public Direction(double latitude, double longitude, String written) {
           lng = longitude;
           lat = latitude;
           txt = written;

        }//direction class
    //TODO: Fill In Methods Etc.

Hope this helps.


Here is the whole project:
Map with Directions Example
(54.22 KiB) Downloaded 80 times
Master Developer
Master Developer
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Use the google Navigation app in my own app

Postby Chri » Fri Feb 17, 2012 10:06 am

Hey Phyll,

your heard from me, but not in this thread :).
You answered a few questions of mine too (in other threads (like that one with the application start after boot up)).

The source you have found is quite good.
I also coded something like this and to draw the route is not the problem.

The bugs come, if you rotate the map on the x- Axis.
If you do so (while the route is drawn) and then scroll around there come up a lot of strange lines or planes just complete random.
That´s a main problem.

wkr Chri
Experienced Developer
Experienced Developer
Posts: 51
Joined: Mon Aug 31, 2009 12:08 pm

Re: Use the google Navigation app in my own app

Postby Phyll » Fri Feb 17, 2012 1:22 pm

Hi Chris,

As you may have noticed I try to keep a lot of balls in the air at once on this board. Maybe I should say "in the error". Anyway I might have recognized your handle but forgotten the individual threads. Sorry if that caused you any trouble.

It would be hard for me to tell you why some code you have written does not work well. It is always a tricky business to have Android change orientation, be paused and sent to the background, be disconnected from the host or any number of things that leaves some or all of the variables undefined or something. I would say this about the directions and the way this piece of code works. Once you have received these directions they are stored as latitude and longitude points, so that you should always be able to redraw them exactly the same way at any rendering of the map. If there are any problems with the placement of these endpoints on the map it is because something has gone wrong getting the screen coordinates from Google's routines.

But if you ever want to pick it up again, that code is a good start.

Master Developer
Master Developer
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Use the google Navigation app in my own app

Postby Chri » Fri Feb 17, 2012 1:28 pm

Thank you Phyll,

I will keep that in mind.

wkr Chri
Experienced Developer
Experienced Developer
Posts: 51
Joined: Mon Aug 31, 2009 12:08 pm


Re: Use the google Navigation app in my own app

Postby hgft » Wed Feb 29, 2012 9:56 am

Coach Outlet Online Sale is with imperfections which consist of cuts, scars, and scratches will exist, the grain in its organically grown problem has between one of the most considerable dietary fibers strength, and getting a last end result between one of the most considerable durability. The grain also has organically grown breathability, resulting in increased comfort using the path from the wearer.

Louis Vuitton Outlet could possibly be one of the most well-known is not necessarily one of the most ideal for you! possibly the most current quarter round shoulder bag with fluorescent color provides you a shine in the moment, desire to possess the urge to it immediately; But possibly your pores and skin color could possibly be the earth beside the handbag could possibly be one of the most make you fondle admiringly joker choice.

Louis Vuitton Outlet supply reduce, the weakening from the role, tiny haystack in slender whole body once more and again. the right way to purchase Louis Vuitton bags That's between the powerful cohesion when Cunningham lancelet find yourself isolated point, allow wind and bad weather insulation, yr pursuing year, pile of grass system earlier short increased grass blanketed with it or bi erosion.

Jennifer Garner and Ben Affleck are the proud parents of a newborn son! The 39-year-old actress gave birth to the couple's third child in Santa Monica, Calif., a source tells Us Weekly. The family's newest addition joins older sisters Violet, 6, and Seraphina, 3. “I would have thought [Ben] wanted a boy]. At first … I really thought so,” Jen, who kept the baby's gender under wraps, told Jay Leno last month.
Experienced Developer
Experienced Developer
Posts: 66
Joined: Tue Feb 28, 2012 9:11 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 10 guests