Jems
Jems

Reputation: 33

Search nearby hospital via google map intent (Android)

I need to search nearby child hospital and find the root from button click using intent,

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                        Uri.parse("http://maps.google.com/maps?&saddr="
                                + x
                                + ","
                                + y
                                + "&daddr=nearby child hospitals"

                                ));
                        startActivity(intent);

x,y as current lat and long.

It will show the hospitals are not in my current location(Shows different country hospitals) Then, I click back button, then click Get Directions button means (From text box contains my source lat and long, Destinations text box contains nearby child hospitals), it shows my nearer child hospitals.

Is there any way do to this in first (i.e., intent call)?

Upvotes: 0

Views: 3749

Answers (3)

Null Pointer Exception
Null Pointer Exception

Reputation: 1583

 Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + query);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(gmmIntentUri.toString()));
        intent.setPackage("com.google.android.apps.maps");
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            try {
                Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(gmmIntentUri.toString()));
                context.startActivity(unrestrictedIntent);
            } catch (ActivityNotFoundException innerEx) {
                Toast.makeText(context, "Please install a maps application", Toast.LENGTH_LONG).show();
            }
        }

Upvotes: 2

Esthinov
Esthinov

Reputation: 1

you can use this code, intent open a map and automatic search hospital near me

String uri = "geo:"+ x + "," + y +"?q=hospitals+near+me";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));

Upvotes: 0

Adil Soomro
Adil Soomro

Reputation: 37729

You can use "geo:" URL scheme to open maps and then search nearby hospitals like this:

String uri = "geo:"+ x + "," + y +"&q=child hospitals";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));

For documentation reference, see Invoking Google Applications on Android Devices

Upvotes: 2

Related Questions