How to search specific nearby places - java

I am creating a Google Maps app. In my app I am searching for nearby ATMs by using Places type "ATM". It all works perfectly, but I have to find specific nearby ATMs such as Axis bank ATMs. So how do I do this?

I have implemented the same in my app . Use the following function for the same:
private void showNearbyAtms(){
Uri mapIntentUri = Uri.parse("geo:0,0?q= Axis atm");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (getActivity() != null && mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(mapIntent);
}
}

Related

How to make google maps coordinates works on specific country. - Android

I am android developer, and i am working on application such as Uber, Careem, etc.
I have a functionality using the google map, to let the user to set his own marker on particular confidantes.
The problem here is my application is just works on Saudi Arabia only and Jeddah city to be exact. and i am not support any other countries or city expect the above.
I need a solution when the user drop down his marker to display a pop up or something telling him that we are not support this area yet.
Is there any solution.
Thanks,
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* #param context Context reference to get the TelephonyManager instance from
* #return country code or null
*/
public static String getUserCountry(Context context) {
try {
final TelephonyManager mTelephonyManager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = mTelephonyManager.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
return simCountry.toLowerCase(Locale.US);
}
else if (mTelephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
String networkCountry = mTelephonyManager.getNetworkCountryIso();
if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
return networkCountry.toLowerCase(Locale.US);
}
}
}
catch (Exception e) { }
return null;
}

How to get direction navigation in Google maps in android

I want to show navigation direction while clicking the info window.
I tried some code, it shows the Preview button, but it does not show the navigation button.
I got it like in the picture below:
But, I want it like this:
Here my code:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?" +
"saddr="+ gps.latitude + "," + gps.longitude + "&daddr=" + marker.getPosition().latitude + "," +
marker.getPosition().longitude+ "&sensor=false&units=metric&mode=driving"));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
You can follow this documentation on how to launch Google Maps navigation with turn-by-turn directions to the address or coordinate specified.
Here is a sample Intent which requests turn-by-turn navigation to Taronga Zoo, in Sydney Australia:
Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Check these related SO threads:
Is there an API for Google Maps navigation in Android?
Android Google Maps API v2 start navigation

how to get all music players

I want to query all activitys that can play a music file.
I have tried to get all music players like this:
Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setType("audio/*");
packages = getPackageManager().queryIntentActivities(resolve_intent, 0);
if (packages == null || packages.size() <= 0)
{
//none found
}
but i everytime get an empty (or null) list...
if i do this for type = "image/* or "video/*"
i get all applications that can handle this type.
only for "audio/*" i get no players installed, even if i know that there is one...
so what am i doing wrong?
Fond it myself:
i forgot to set the Data, and i didn't know android uses the data too
to resolve the matching intents...
working code:
Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setDataAndType(Uri.fromFile(new File("/some/path/to/a/file")), "audio/*");
List<ResolveInfo> packages = context.getPackageManager().queryIntentActivities(resolve_intent, 0);

How can I programmatically open a user specified calling/sms/mms Android app?

I've created an address book app, and am trying to add some features to it. What I'm trying to do right now is add the ability to longclick a phone number, and then either call/text/mms the number. This all works fine with phones, but I was wondering how to do this on tablets, since they will not have that same ability. The device I'm debugging on is a tablet, and I use HeyWire for texting. I know there are apps out there for calling via WiFi as well. Here's what I have so far for the texting section of my switch statement:
case 1: //SMS
if(CanCallAndText)
{
CustomSMSDialog SendSMSDialog = new CustomSMSDialog(BrowseListActivity.this, ParsedPhoneNum);
SendSMSDialog.setTitle("Sending text to " + PhoneNum);
SendSMSDialog.setCancelable(false);
SendSMSDialog.show();
}
else
{
try
{
Intent WiFiSMS = new Intent(Intent.ACTION_VIEW);
WiFiSMS.setData(Uri.parse("sms:" + PhoneNum));
WiFiSMS.setType("vnd.android-dir/mms-sms");
startActivityForResult(Intent.createChooser(WiFiSMS, ""), 0);
}//endtry
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}//endcatch
}//endelse
break;
I don't know if I'm doing the create chooser incorrectly or not, but it simply tells me that no apps can handle it. Thank you!
EDIT: Ooh, spotted a slight error that I should fix tomorrow. The URI should include ParsedPhoneNum, instead of PhoneNum. Anything other than a number, like a -, would be included in PhoneNum.

How to open Google Maps using address?

How can I open Google Maps(using Intents or adding Google Maps into my application) with address? I have the address, but I don't have latitude/longitude. How can I do it? Thank you.
use below code,
String map = "http://maps.google.co.in/maps?q=" + str_location;
// where str_location is the address string
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
startActivity(i);
From my personal Code Library. ;)
public static Intent viewOnMap(String address) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:0,0?q=%s",
URLEncoder.encode(address))));
}
public static Intent viewOnMap(String lat, String lng) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:%s,%s", lat, lng)));
}
String geoUri = "http://maps.google.com/maps?q=loc:" + addressName;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
context.startActivity(intent);
Change the bold part of this URL to your company address. It's best if you replace all spaces with a plus (+) character, but should work with spaces too:
http://maps.google.com/maps/geo?q=620+8th+Avenue,+New+York,+NY+10018,+USA&output=csv&oe=utf8&sensor=false
Raise a request to above URL. For more information refer http://androidadvice.blogspot.in/2010/09/asynchronous-web-request.html
This will generate a code that looks something like this:
200,8,40.7562008,-73.9903784
The first number, 200, says that the address is good. The second number, 8, indicates how accurate the address is. The last two numbers, 40.7562008 and -73.9903784, are the latitude and longitude of this address. Use these to get your google map working.
Note : The above steps have been copied from http://webdesign.about.com/od/javascript/ss/add-google-maps-to-a-web-page_2.htm
You can use Google Geocoding API, which converts your physical address into latitude and longitude. API returns it into XML or JSON format. You just need to parse the data to get latitude and longitude. After receiving latitude and longitude you can load it on mapview.
Geocoding api link :
https://developers.google.com/maps/documentation/geocoding/
Hope this helps.
As of 2017 the recommended by Google approach is using the Google Maps URLs API that provides universal cross-platform URLs. You can use these URLs in your intents.
Example of such URL from the documentation:
https://www.google.com/maps/search/?api=1&query=centurylink+field
Hope this helps!
Little late to the party. I prefer #st0le's answer but URLEncoder.encode(String s) is deprecated as of API 16. You need to pass a second argument as well. Check the answer below.
public static Intent viewOnMapA(String address) {
try {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:0,0?q=%s",
URLEncoder.encode(address, "UTF-8"))));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
From the current documentation
https://developers.google.com/maps/documentation/urls/get-started
It is better to use
https://www.google.com/maps/dir/?api=1&query=address
so:
val address = "some address"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/maps/dir/?api=1&query=$address"))
startActivity(intent)

Categories

Resources