0

I've been on this for over a week. I've tried setting up a Google maps activity in my app with no luck. I also see you can call on the Google map app from your application. By using a Onclicklistener. How do I open the Google Maps app from my app using a button? This is the code I'm using...

import com.google.android.maps.GeoPoint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Store10 extends Activity {

    Context context;
    GeoPoint geo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store10);

        Button num10 = (Button) findViewById(R.id.pNumber10);
        Button nav10 = (Button) findViewById(R.id.Map10);

        num10.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // TODO Auto-generated method stub
                Intent myIntent = new Intent(view.getContext() ,Num10.class);
                startActivityForResult(myIntent, 0);
            }
        });
        nav10.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // TODO Auto-generated method stub
                String uri = String.format("geo:%f,%f",40,325874,76,002211);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                context.startActivity(intent);
            }
        });
    }

}

Here's the Onclicklistener I'm trying to set up

nav10.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // TODO Auto-generated method stub
                String uri = String.format("geo:%f,%f",40,325874,76,002211);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                context.startActivity(intent);
            }
        });
RivieraKid
  • 5,923
  • 4
  • 38
  • 47
KodiakBear211
  • 181
  • 2
  • 3
  • 13

5 Answers5

5

you can try these line of code...

String uri = "http://maps.google.com/maps?saddr=" + "9982878"+","+"76285774"+"&daddr="+"9992084"+","+"76286455";
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            startActivity(intent);  
Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38
  • I think this should work for me. Wish it placed a marker over the loc. Cuz some of the loc's I have are in shopping centers. If you know of a way to place a marker on the loc, let me know then... – KodiakBear211 May 03 '12 at 12:47
3

Change Uri to set the zoom level

uri = Uri.parse("geo:37.827500,-122.481670"?z=10"); 

Try this to add Marker:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);

You can omit (Label+Name) if you don't want a label, and it will choose one randomly based on the nearest street or other thing it thinks relevant.

Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
3

This is how i did it...

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"geo:"    + marker.getPosition().latitude +
","       + marker.getPosition().longitude +
"?q="     + marker.getPosition().latitude +
","       + marker.getPosition().longitude +                                   
"("       + marker.getTitle() + ")"));

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
2

//---Show Map button---

 b3 = (Button) findViewById(R.id.btn_showMap);
 b3.setOnClickListener(new OnClickListener()
 {
 public void onClick(View arg0){
 Intent i = new
 Intent(android.content.Intent.ACTION_VIEW,
 Uri.parse("geo:37.827500,-122.481670"));
 startActivity(i);
 }
 });
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
  • Thanks that did work. But i have a question. when it goes to the map. when set in satellite its to close and you have to zoom out once to see the location. Can you set the zoom? another can you set a marker using this method. Or do you have to build a map in your app to do something like this? – KodiakBear211 May 03 '12 at 07:32
1

Please check here this URL maybe helpful for you..

Uri uri = Uri.parse("geo:13.070984,80.253639");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
startActivity(in);
Community
  • 1
  • 1
Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38