Google Maps Link Broken By Symbols - android

I am developing an emergency application for my school, and I had a question. I have code that gets your coordinates, and smsmanager sends them to a designated phone number. I tried to put the coordinates in a Google Maps link so the recipient can just click a link instead of inputting the coordinates into Google Maps, but when I do, the link is broken by the "=", "<" and ">" signs. I was wondering what I could do in my code to make the link work. When the recipient receives the message, it looks like this..
"http://maps.google.com/?q"=<"######">,<"######">
Everything in quotations is a link, the rest is not.
public void onClick(View v) {
try {
txtLat = (TextView) findViewById(R.id.textview1);
String messageToSend = txtLat.getText().toString();
String number = "8143664050";
SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
Toast.makeText(getApplicationContext(), "Help SMS Sent",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS failed!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
#Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("http://maps.google.com/?q=<" + location.getLatitude() + ">,<" + location.getLongitude() + ">");
}

try:
int zoom = 12;
txtLat.setText(
"https://www.google.com/maps/#" + location.getLatitude() + "," +
location.getLongitude() + "," + zoom + "z");
for 3d/satellite map:
txtLat.setText(
"https://www.google.com/maps/#" + location.getLatitude() + "," +
location.getLongitude() + ",15000m/data=!3m1!1e3");
The address should be automatically updated when you are using Google Maps, try around and see how it changes.

Related

Getting some weird strings while i was trying to get location name using marker on touch event on maps

I'm trying to make an app to get the location name where the marker is placed on the map in android. When I used marker.position() function it gave me a weird string. Starts with, com.google.android.gms.maps.model.MarkerOptions#28f817d
I tried to use geocode but didn't work for me. I might be using it in an improper way.
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng point) {
mMap.clear();
MarkerOptions marker = new MarkerOptions();
mMap.addMarker(marker.position(point)
.draggable(true)
.title(String.valueOf(marker.position(point)))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.snippet(point.latitude + "," + point.longitude));
}
});
}
I wish that I can get the location name on the title.
Thats becouse marker.position(point)) returns an object of class LatLng and is not an String itself. You could use any of its properties (latitude & longitude):
String.valueOf(marker.position(point))
to
"" + marker.position(point).latitude + marker.position(point).longitude
Do something like this
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng point) {
mMap.clear();
MarkerOptions marker = new MarkerOptions();
mMap.addMarker(marker.position(point)
.draggable(true)
.title(getAddress(point.getLatitude(),point.getLongitude()))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.snippet(point.latitude + "," + point.longitude));
}
});
}
write a function called getAddress like this
public string getAddress(double lat, double lng) {
Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + "\n" + obj.getCountryName();
add = add + "\n" + obj.getCountryCode();
add = add + "\n" + obj.getAdminArea();
add = add + "\n" + obj.getPostalCode();
add = add + "\n" + obj.getSubAdminArea();
add = add + "\n" + obj.getLocality();
add = add + "\n" + obj.getSubThoroughfare();
Log.v("IGA", "Address" + add);
// Toast.makeText(this, "Address=>" + add,
// Toast.LENGTH_SHORT).show();
// TennisAppActivity.showDialog(add);
return add;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return e;
}
}

How do I get the string array from a Notification bundle?

I have an app that reads notifications to the driver while driving. I am trying to parse the various notifications. Those that use the old 'tickerText' work fine but several apps like Skype don't support that. Instead, the text in the notification after the first message just says something like "3 new messages". Not very helpful. I want the last message string instead. I wrote this:
public class Catcher extends NotificationListenerService {
File file;
String dir;
File save;
int count = 0;
#Override
public void onCreate() {
super.onCreate();
dir = Environment.getExternalStorageDirectory() + "/NotCatch";
save = new File(dir);
if(!save.exists()){
save.mkdirs();
}
//Toast.makeText(this, dir + " " + file.getName(), Toast.LENGTH_LONG).show();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
file = new File(save, "NotCatch" + count + ".txt");
count++;
String temp = "";
String[] lines;
Notification not = sbn.getNotification();
temp += "Category: " + not.category+ "\n";
temp+= "TickerText: " + not.tickerText + "\n";
temp += "Extras..."+ "\n";
Bundle bun = not.extras;
temp+= "BigText: " + bun.getString(Notification.EXTRA_BIG_TEXT)+ "\n";
temp+= "SummaryText: " + bun.getString(Notification.EXTRA_SUMMARY_TEXT)+ "\n";
temp+= "InfoText: " + bun.getString(Notification.EXTRA_INFO_TEXT)+ "\n";
temp+= "Text: " + bun.getString(Notification.EXTRA_TEXT)+ "\n";
temp+= "TextLines: " + bun.getString(Notification.EXTRA_TEXT_LINES)+ "\n";
temp+= "SubText: " + bun.getString(Notification.EXTRA_SUB_TEXT) + "\n";
temp+= "Title:" + bun.getString(Notification.EXTRA_TITLE) +"\n";
temp+= "Big Title:" + bun.getString(Notification.EXTRA_TITLE_BIG) +"\n";
/* lines = bun.getString(Notification.EXTRA_TEXT_LINES).split("\n");
temp += "Lines... \n" ;
int cnt = 0;
for (String line : lines) {
temp+= cnt + ": " + line + "\n";
cnt++;
}*/
Looper.prepare();
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(temp.getBytes());
fos.close();
Toast.makeText(this,"File written", Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
This is just what I have so far for testing of course. I can get the bundle from the notification but it can't get the string array of the message lines. It looks like this in the debugger. 'bun' below is the 'Bundle' from the 'Notification'.
My question is this. How do I get the array of strings that start with "some message text - 4"? This is the bundle from an Android Notification.
I finally was able to get the strings this way
CharSequence[] lines = bun.getCharSequenceArray(Notification.EXTRA_TEXT_LINES);
for(CharSequence line : lines){
temp+= "line: " + line.toString() + "\n";
}
Since the strings you are trying to retrieve are contained in the ArrayMap mMap (according to the debugger image), and as implementations of Map are serializable, you'll want to do the following to first retrieve that map:
ArrayMap map = bun.getSerializableExtra("mMap");
Then, you should be able to get the array of strings you want (which according to the debugger image is an array of CharSequence objects) with the following:
CharSequence[] messages = (CharSequence[]) map.valueAt(1);
An interesting read on bundles and maps:
https://medium.com/the-wtf-files/the-mysterious-case-of-the-bundle-and-the-map-7b15279a794e#.kf3m2haa3

Getting a place name in google map in android

I have a requirement that whenever I drag/browse the Google map and place a marker on it, it should display the name of the place(where the marker is placed) in an AutocompleteTextview. I have checked out the Places API and the Geocoder class but i least understood it. I need to do the task same as that of the Places tab in the life360 app. How can I achieve it?
try this it may help you...
When u mark a place, try to capture latitude & longitude with marker & use this code to get location name
public String getAddress(Context context, double lat, double lng) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + "\n" + obj.getCountryName();
add = add + "\n" + obj.getCountryCode();
add = add + "\n" + obj.getAdminArea();
add = add + "\n" + obj.getPostalCode();
add = add + "\n" + obj.getSubAdminArea();
add = add + "\n" + obj.getLocality();
add = add + "\n" + obj.getSubThoroughfare();
return add;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
}
Try this I hope Its work.
public void getLocation(double lat, double lng) {
Geocoder geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
Log.e("IGA", "Address" + add);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}

Not getting Email Address from linkedin?

I m trying to get email address from linkedin user after authenticate now i m getting basic profile but not getting email address.
I m using http://code.google.com/p/linkedin-j/downloads/list jar file for authentication.
i have read this document care fully but not use full for me http://oodlestechnologies.com/blogs/recent-changes-in-linkedin-api.
Below code for jar file properties :-
# API URLs
##########
# Profile API
com.google.code.linkedinapi.client.getProfileForCurrentUser=http://api.linkedin.com/v1/people/~{profileFields}
com.google.code.linkedinapi.client.getProfileById=http://api.linkedin.com/v1/people/id={id}{profileType}{profileFields}
com.google.code.linkedinapi.client.getProfileByUrl=http://api.linkedin.com/v1/people/url={url}{profileType}{profileFields}
#OAuth URLs
###########
com.google.code.linkedinapi.client.oauth.requestToken=https://api.linkedin.com/uas/oauth/requestToken
com.google.code.linkedinapi.client.oauth.accessToken=https://api.linkedin.com/uas/oauth/accessToken
com.google.code.linkedinapi.client.oauth.authorize=https://www.linkedin.com/uas/oauth/authorize
com.google.code.linkedinapi.client.oauth.invalidateToken=https://api.linkedin.com/uas/oauth/invalidateToken
when i m change on anything on above and creating jar its show error.
now i m shown my code :-
void startAutheniticate() {
System.out.println("OAUTH_CALLBACK_URL " + OAUTH_CALLBACK_URL);
final LinkedInRequestToken liToken = oAuthService
.getOAuthRequestToken(OAUTH_CALLBACK_URL);
final String uri = liToken.getAuthorizationUrl();
getSharedPreferences(OAUTH_PREF, MODE_PRIVATE).edit()
.putString(PREF_REQTOKENSECRET, liToken.getTokenSecret())
.commit();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
void finishAuthenticate(final Uri uri) {
if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
final String problem = uri.getQueryParameter(OAUTH_QUERY_PROBLEM);
if (problem == null) {
final SharedPreferences pref = getSharedPreferences(OAUTH_PREF,
MODE_PRIVATE);
final LinkedInAccessToken accessToken = oAuthService
.getOAuthAccessToken(
new LinkedInRequestToken(uri
.getQueryParameter(OAUTH_QUERY_TOKEN),
pref.getString(PREF_REQTOKENSECRET,
null)),
uri.getQueryParameter(OAUTH_QUERY_VERIFIER));
pref.edit()
.putString(PREF_TOKEN, accessToken.getToken())
.putString(PREF_TOKENSECRET,
accessToken.getTokenSecret())
.remove(PREF_REQTOKENSECRET).commit();
showCurrentUser(accessToken);
} else {
Toast.makeText(this,
"Appliaction down due OAuth problem: " + problem,
Toast.LENGTH_LONG).show();
finish();
}
}
}
void clearTokens() {
getSharedPreferences(OAUTH_PREF, MODE_PRIVATE).edit()
.remove(PREF_TOKEN).remove(PREF_TOKENSECRET)
.remove(PREF_REQTOKENSECRET).commit();
}
void showCurrentUser(final LinkedInAccessToken accessToken) {
final LinkedInApiClient client = factory
.createLinkedInApiClient(accessToken);
try {
final Person profile = client.getProfileForCurrentUser(EnumSet.of(
ProfileField.ID, ProfileField.FIRST_NAME,
ProfileField.LAST_NAME, ProfileField.HEADLINE,
ProfileField.INDUSTRY, ProfileField.PICTURE_URL,
ProfileField.DATE_OF_BIRTH, ProfileField.LOCATION_NAME,
ProfileField.MAIN_ADDRESS, ProfileField.LOCATION_COUNTRY
));
// /////////////////////////////////////////////////////////
// here you can do client API calls ...
// client.postComment(arg0, arg1);
// client.updateCurrentStatus(arg0);
// or any other API call (this sample only check for current user
// and shows it in TextView)
// /////////////////////////////////////////////////////////
System.out.println("p => " + profile);
System.out.println("PersonID : " + profile.getId());
System.out.println("Name : " + profile.getFirstName() + " "
+ profile.getLastName());
System.out.println("Headline : " + profile.getHeadline());
System.out.println("Industry : " + profile.getIndustry());
System.out.println("Picture : " + profile.getPictureUrl());
DateOfBirth dateOfBirth = profile.getDateOfBirth();
System.out.println("DateOfBirth : " + dateOfBirth.getDay() + "/"
+ dateOfBirth.getMonth() + "/" + dateOfBirth.getYear());
System.out.println("MAin Address : " + profile.getMainAddress());
Location location = profile.getLocation();
System.out.println("Location:" + location.getName() + " - "
+ location.getCountry().getCode());
// get_from_last
Toast.makeText(LITestActivity.this, "Wait...", Toast.LENGTH_LONG).show();
startActivity(new Intent(LITestActivity.this,
UserProfileScreen.class)
.putExtra("get_from_last", "1")
.putExtra("getId", profile.getId())
.putExtra("getEmail", "email#add.com")
.putExtra("getFirstName", profile.getFirstName())
.putExtra("getLastName", profile.getLastName())
.putExtra("getHeadline", profile.getHeadline())
.putExtra("getPictureUrl", profile.getPictureUrl())
.putExtra(
"dob",
dateOfBirth.getDay() + "/" + dateOfBirth.getMonth()
+ "/" + dateOfBirth.getYear()));
finish();
} catch (LinkedInApiClientException ex) {
clearTokens();
Toast.makeText(
this,
"Appliaction down due LinkedInApiClientException: "
+ ex.getMessage()
+ " Authokens cleared - try run application again.",
Toast.LENGTH_LONG).show();
pd.dismiss();
finish();
}
}
int i = 0;
public void onNewIntent(Uri intent) {
if (i == 0) {
i++;
finishAuthenticate(intent);
} else {
i++;
}
System.out.println("i => " + i);
}
but i m stuck how to get email address so can any one help me
Even though its an old question, I think its worth to answer. I struggled a lot to find a way to fetch user email address from linkedin using linkedin-j-android library. Unfortunately I could not find any ready to use solution, so I made changes in the library sources and re-packaged it to use in my app. You can download the library from this link:
https://dl.dropboxusercontent.com/u/46373731/linkedin-j-android.jar
You can use ProfileField.EMAIL_ADDRESS to fetch email-address.

how to find longitude and latitude of particular location?

How to find Longitude and Latitude of Particular location?
the location is entered by user in edittext & click on search button then the location is display in googlemap.
i used following code for that but this is give error "Service not Available"
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
address=geoCoder.getFromLocationName(txtlocation.getText().toString(), 1).get(0);
double longi=address.getLongitude();
double latit=address.getLatitude();
System.out.println("longitude:--- " +longi);
System.out.println("latitude:---" +latit);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(MapRouteActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
try to use
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude(); double latitude = location.getLatitude();
The call to getLastKnownLocation() doesn't block - which means it will return null if no position is currently available - so you probably want to have a look at passing a LocationListener to the requestLocationUpdates() method instead, which will give you asynchronous updates of your location.
private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { longitude = location.getLongitude(); latitude = location.getLatitude(); } }
lm.requestLocationUpdates(LocationManager.GPS, 2000, 10, locationListener);
You'll need to give your application the ACCESS_FINE_LOCATION permission if you want to use GPS.
You may also want to add the ACCESS_COARSE_LOCATION permission for when GPS isn't available and select your location provider with the getBestProvider() method.
try this code
public static String getLatLng(Context context,String addr){
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
String add = "";
try{
List<Address> addresses = geocoder.getFromLocationName(addr, 5);
for(int i=0;i<1;i++){
Address obj = addresses.get(i);
for(int j=0;j<obj.getMaxAddressLineIndex();j++){
add = obj.getAddressLine(j);
add = add + "\nCountryName " + obj.getCountryName();
add = add + "\nCountryCode " + obj.getCountryCode();
add = add + "\nAdminArea " + obj.getAdminArea();
add = add + "\nPostalCode " + obj.getPostalCode();
add = add + "\nSubAdminArea " + obj.getSubAdminArea();
add = add + "\nFeatureName " + obj.getFeatureName();
add = add + "\nLocality " + obj.getLocality();
add = add + "\n" + obj.getSubThoroughfare();
add = add + "\nurl " + obj.getUrl();
add = add + "\nLatitude " + obj.getLatitude();
add = add + "\nLongitude " + obj.getLongitude();
}
add = add+"\n";
}
Log.v("IGA", "Address" + add);
}catch(Exception e){
e.printStackTrace();
add = e.toString();
}
return add;
}

Categories

Resources