intent putextra map android - 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();
}

Related

passing data to infowindowclick google maps

I've declared current location latlong and selected location latlong. I want to pass these latlong to onInfoWindowClick().
When I try to use Toast to get the data that I set from marker.setTag(mLatitude) and marker.seTag(mLongitude), It give me the same data only mLongitude. Can anyone help me, please.
This is my code:
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
if (parent.getItemAtPosition(position).toString() != "-- Pilih ATM --"){
mMap.clear();
String pilih_atm = (String) parent.getItemAtPosition(position);
// Toast.makeText(getActivity(), pilih_atm, Toast.LENGTH_SHORT).show();
SQLiteDatabase db = dbHelper.getReadableDatabase();
cursor = db.rawQuery("SELECT * FROM atm WHERE atm_name = '" + pilih_atm + "'",null);
if (cursor != null){
while (cursor.moveToNext()){
title = cursor.getString(1).toString();
__global_endposition = cursor.getString(2).toString();
String[] exp_endCoordinate = __global_endposition.split(",");
double lat_endposition = Double.parseDouble(exp_endCoordinate[0]);
double lng_endposition = Double.parseDouble(exp_endCoordinate[1]);
LatLng endx = new LatLng(lat_endposition, lng_endposition);
MarkerOptions options = new MarkerOptions();
options.position(endx);
options.title(title);
options.snippet(__global_endposition);
if (title.equals("ATM BNI")){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
}else if(title.equals("ATM BCA")){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}else if(title.equals("ATM Mandiri")){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
}
Marker marker = mMap.addMarker(options);
marker.setTag(mLatitude);
marker.setTag(mLongitude);
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(getActivity()));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
// I want to get current location LatLong and selected location LatLong
// I want execute the LatLong on this method
// this just for testing
Toast.makeText(getActivity(), "LatLng: "+marker.getTag()+", "+marker.getTag(), Toast.LENGTH_SHORT).show();
}
});
}
if (!cursor.isClosed()) {
cursor.close();
cursor = null;
}
}
}
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
This is because Marker object has only one Tag object and when you call .setTag() second time, you overrides previously set tag object:
Marker marker = mMap.addMarker(options);
marker.setTag(mLatitude); // tag = mLatitude
marker.setTag(mLongitude); // tag overrides, and now tag = mLongitude
The one of solution is:
Marker marker = mMap.addMarker(options);
marker.setTag("" + mLatitude + "," + mLongitude); // tag now is string: "mLatitude, mLongitude"

can i set LatLngObject in PlacePicker.IntentBuilder to see that place in map?

My code is this. it is working fine.
How can i set Latitude and Longitude in PlacePicker.IntentBuilder so that i can see the location in map
try {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Intent intent = builder.build(MainActivity.this);
startActivityForResult(intent, PLACE_PICKER_REQUEST_CODE);
} catch (GooglePlayServicesRepairableException
| GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST_CODE) {
final Place place = PlacePicker.getPlace(this, data);
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
Khet_Location = address.toString();
Place_Name = name + "," + address;
String attributions = (String) place.getAttributions();
if (attributions == null) {
attributions = "";
}
current_location_id.setVisibility(View.VISIBLE);
current_location_id.setText(Place_Name);
Double latitude = place.getLatLng().latitude;
Double longitude = place.getLatLng().longitude;
Address_lat = String.valueOf(latitude);
Address_long = String.valueOf(longitude);
}else
super.onActivityResult(requestCode, resultCode, data);
}
Please help me out.
You means focus all place pickers, i don't understand very well you question...
but check this...
setLatLngBounds(LatLngBounds latLngBounds)
example
for i to n{
array coords
add in LatLngBounds
}
placepicker.setLatLngBounds(latLngBounds)

Variable Stays Null

I'm trying to pass a String between activities, From YtAdapter to Favorites.
YtAdapter:
mHolder.mVideoFavorite.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//////////////////////////////////////////////////////////////
// Need to send SearchResult result from here to favorites //
////////////////////////////////////////////////////////////
AppUtils.showToast(result.getSnippet().getTitle() + " Was added to favorites.");
Intent intent = new Intent(mActivity,Favorites.class);
String vidId,vidTitle,vidThumbnail;
vidId = result.getId().getVideoId(); //Video ID
vidTitle = result.getSnippet().getTitle(); //Video Title
vidThumbnail = result.getSnippet().getThumbnails().getMedium().getUrl(); //Video Thumbnail
intent.putExtra("id",vidId);
intent.putExtra("title",vidTitle);
intent.putExtra("thumbnail",vidThumbnail);
}
});
And try to get it in Favorites:
/*Getting video information from YtAdapter*/
vidID = getIntent().getStringExtra("id"); <--- Stays null
vidTitle = getIntent().getStringExtra("title"); <--- Stays null
vidThumbnail = getIntent().getStringExtra("thumbnail"); <--- Stays null
I'm accessing Favorties from 3rd activity, not straight from YtAdapter.
try this in your main class:
Intent i = new Intent(ListViewActivity.this, EditContact.class);
Bundle bundle = new Bundle();
bundle.putInt("index", itemId);
bundle.putBoolean("AddContact", false);
i.putExtras(bundle);
startActivity(i);
and you can get your data in the other class like this:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
Int index = bundle.getInt("index");
Boolean bool = bundle.getBoolean("AddContact");
if (bool ) {
setTitle("Add Contact");
} else {
setTitle("Edit Contact");
}
I hope it will help.
you can force all of your parameter be a string value:
intent.putExtra("id",vidId +"");
intent.putExtra("title",vidTitle+"");
intent.putExtra("thumbnail",vidThumbnail+"");
probally they aren't and you are getting with "getStringExtra".
but the better options is you use te correct "getter" of extra.
---Edit---
you can check in your activity the keys and values this way:
for(String key : getIntent().getExtras().keySet()){
Log.d("TEST", "key: " + key);
Log.d("TEST", "value: " + getIntent().getExtras().get(key));
}

How can I put a name to a location

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);

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.

Categories

Resources