How can I put a name to a location - android

I have this code to show my location to another location but it's not the issue, how can I add a name for it?
locationname.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String DESTINATION_LOCATION = "37.967775, 23.720689";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="
+ "&daddr=" + DESTINATION_LOCATION));
startActivity(intent);
}
});
I have this:
String DESTINATION_LOCATION = "My location name";
But it doesn't fit in the code!
Does anybody know?
Thanks

This will open with default map and adds marker with name
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
Option 2
String urlAddress = "http://maps.google.com/maps?q="+ myLatitude +"," + myLongitude +"("+ labelLocation + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress);
startActivity(intent);

Related

intent putextra map android

Activity <- first , I want to intent.putExtra (data) ...
but it's only put only one marker ...
it's not put (data) many marker ???
Help me, pllz ??
Marker marker = map.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(bmp))
.position(new LatLng(dataLat,dataLong)).title(dataTitle)
.snippet(dataAddress));
allMarkersMap.put(marker, DetailActivity.class);
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
Class cls = allMarkersMap.get(marker);
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,cls);
intent.putExtra("Title",dataTitle);
// Toast.makeText(getBaseContext(), phone + "-"+ dataTitle +"-"+ dataAddress + "-" , Toast.LENGTH_SHORT).show();
startActivity(intent);
Activity <- second
Intent intent = getIntent();
tvtitle = (TextView)findViewById(R.id.tvTitle);
Bundle bundle = intent.getExtras();
String dataTitle = bundle.getString("Title");
((TextView)findViewById(R.id.tvTitle)).setText("Title: " + dataTitle);
// Toast.makeText(getBaseContext(),title, Toast.LENGTH_SHORT).show();
}

Skype application is not running

When I added a button it should take me to skype application to a user (name_here) .. if Skype didn't exist on my mobile, it goes to https://play.google.com/store/apps/details?id=com.skype.raider
The code is
raskypelink.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (uri.contains("https://www.skype.com/" )) {
String name_here = "name_here";
String uri1 = "skype://Page/" + name_here;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri1));
startActivity(intent);
} else {
String skype = "skype";
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider" + skype;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri1));
startActivity(i);
}
}
});
Please help!
For IF
Android Docs - http://developer.skype.com/skype-uris/skype-uri-tutorial-android
For ELSE
Change from
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider" + skype;
to
Remove + skype
String uri1 = "https://play.google.com/store/apps/details?id=com.skype.raider";

update map dircetions in android after specific time?

I am working on an android map app.I am getting direction from latitude and longitude.
But the problem is this i want to update map directions after some time or after location change.
My code is below can any one help me in this.
Button.OnClickListener addressclick = new Button.OnClickListener(){
#Override
public void onClick(View v) {
/*TextView tv = (TextView)v;
String latitude ="0";
String longitude = "0";
String label = "Location";
String uriBegin = "geo:" + latitude + "," + longitude;
String query = tv.getText().toString() + "(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery+"&z=10";
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);*/
TextView tv = (TextView)v;
String addressStr = tv.getText().toString();
Geocoder geoCoder = new Geocoder(context);
try {
List<Address> addresses =
geoCoder.getFromLocationName(addressStr, 1);
if (addresses.size() > 0) {
latitude = addresses.get(0).getLatitude();
longitude =addresses.get(0).getLongitude(); }
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
String directionweburl = "http://maps.google.com/maps?daddr="+Double.toString(latitude)+","+Double.toString(longitude)+"&saddr="+Double.toString(currentlat)+","+Double.toString(currentlong);
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(directionweburl));
myIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(myIntent);
}
};
what am i missing here?anyone can tell?
I think you should start a service and put regular check in it. After some time, you can update map directions or check current location in order to update location info.

send variable latitude longitude to google map direction?

i want to passing variable latitude longitude to google map direction?
can help me see the error or have a new solution?
this is my java code :
public void onClickShowMap(View v) {
String latitude = ((TextView) findViewById(R.id.latitude)).getText().toString();
String longitude = ((TextView) findViewById(R.id.longitude)).getText().toString();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?f=d&daddr="+latitude+","+longitude));
startActivity(intent);
}
Use this code,
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?" + "saddr=" + lat
+ "," + lon + "&daddr=" + lattitude + ","
+longitude));
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
((Activity) this).startActivity(intent);

start navigating to position which is stored in database

I have an application where I am getting the latitude and longitude coordinates.
I want , when to press a button to start navigating to that position .
Now , I am storing latitude and longitude in database.
So , I want to extract the location first.When I press the button to navigate I open an alertdialog and in 'YES' I do:
public void navigation(final View v){
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Do you want to navigate to the saved position?")
.setCancelable(false)
.setPositiveButton("Navigate",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// Action for 'Yes' Button
String query = "SELECT latitude,longitude FROM MEMORIES ";
Cursor c1 = sqlHandler.selectQuery(query);
if (c1 != null && c1.getCount() != 0) {
if (c1.moveToFirst()) {
do {
String mylatitude=c1.getString(c1.getColumnIndex("latitude"));
String mylongitude=c1.getString(c1.getColumnIndex("longitude"));
Double lat=Double.parseDouble(mylatitude);
Double lon=Double.parseDouble(mylongitude);
} while (c1.moveToNext());
}
}
c1.close();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" +
gps.getLocation().getLatitude() + "," +
gps.getLocation().getLongitude() + "&daddr=" + mylatitude + "," + mylongitude ));
startActivity(intent);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Navigation");
alert.show();
}
I have the location stored (lat and lon) and i want to start navigating to that position.
How can I do that?
Thanks!
---------------------UPDATE-------------------------------------
If I do sth like:
String mylat="";
String mylon="";
#Override
protected void onCreate(Bundle savedInstanceState) {
...
...
public void navigation(final View v){
....
String mylatitude=c1.getString(c1.getColumnIndex("latitude"));
String mylongitude=c1.getString(c1.getColumnIndex("longitude"));
mylat=mylatitude;//stored coordinates from database
mylon=mylongitude;
String f="45.08" //current location (start points)
String s="23.3";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" +
f + "," +
s + "&daddr=" + mylat + "," + mylon ));
startActivity(intent);
The intent starts and I am in the map application where the start points are the "f" and "s" I defined above but the destination points are 0.0 , 0.0 ;
So , I have 2 problems:
1) How to put to destination points my stored locations (mylatitude ,mylongitude (which I copy to mylat,mylon)
2) How to get current location (initial points) because my gps class doesn't work on that.
In the example below ImplLocationService is a class/service within my application that is providing the latitude and longitude coordinates of the current location within the device. The Location class is similar to Android's offering but is slightly different and is providing the destination latitude and longitude coordinates. If you were to pull these values from a database, the approach below is the same.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" +
ImplLocationService.getCurrentLocation().getLatitude() + "," +
ImplLocationService.getCurrentLocation().getLongitude() + "&daddr=" +
location.getPoint().latitude + "," + location.getPoint().longitude));
startActivity(intent);
While storing the lat and long store it in this way...
String mylocation=latitude + ":" + longitude;
And while retriving it
String latitude = mylocation.subString(0, myLocation.indexOf(":") - 1 );
String longitude = mylocation.subString(myLocation.indexOf(":"));
and pass it as
j.putExtra("lon", longitude);
j.putExtra("lat", latitude);
one possible way is to store your latitude and longitude values in shared preferences.
-To store values you can use
SharedPreferences sp = getSharedPreferences("MyPrefs", MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("mytext", text);
editor.commit();
-and to retrive those values you can use
String value = prefs.getString("MyPrefs, "mytext");
in your code your are storing latitude and longitudes in double do not forget to convert them in toString()...
hope this helps

Categories

Resources