I am working on an application that sends an e-mail with several information. Among the information is a link to the location of the user to Google Maps. A sample of the link would be:
http://www.google.com.ph/maps/place/14°39'3.8952"N121°2'57.4116"E/#14.651082,121.049281,17z
The code looks like this:
"Google Maps Link: http://www.google.com.ph/maps/place/" +
degToDMS(location.getLatitude()) + "\"N" +
degToDMS(location.getLongitude()) + "\"E/#" +
location.getLatitude() + "," + location.getLongitude() + ",17z");
I converted the degrees longitude and latitude to DMS using a formula I found online and it seemed to be returning good data. However, when I go check the email, the link looks like:
http://www.google.com.ph/maps/place/14°39'3.8952"N121°2'57.4116"E/#14.651082,121.049281,17z
and the hyperlink ends at the first double quote (") right before the N. This is actually a bit irritating and troubling because it doesn't link the entire link properly and it is cut.
How can I escape a double quote in a link? Or is there a better way to link to Google Maps?
I used URLEncode, thanks to for3st for the lead, as such:
final String urlRaw = degToDMS(location.getLatitude()) + "\"N" +
degToDMS(location.getLongitude()) + "\"E/#" +
location.getLatitude() + "," + location.getLongitude() + ",17z";
String encodedURL = "";
try {
encodedURL = URLEncoder.encode(urlRaw, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
where urlRaw is the "problematic' part of your url (where characters don't get escaped properly or something). You DON'T put in the http://.... because it will appear as such http%3A%2F%2Fwww.google.com.ph and yeah you don't want that.
Hence, I only escaped the latter part of my url, the one that starts with the DMS coordinates.
Once I have my encodedURL variable, I simply concat it to the rest of the starting URL as such:
String link = "Google Maps Link: http://www.google.com.ph/maps/place/" + encodedURL;
and not it works.
Related
I'm developing a game with Unity3D for Android. I'm using Facebook App for sharing game score in Facebook. But I receive a error message ;
My codes are here ;
//facebook share start
public static void share(string link, string pictureLink, string name,string caption, string description, string redirectUri){
Application.OpenURL(ShareUrl +
"?app_id=" + AppId +
"&link=" + WWW.EscapeURL( link )+
"&picture=" + WWW.EscapeURL(pictureLink) +
"&name=" + WWW.EscapeURL(name) +
"&caption=" + WWW.EscapeURL(caption) +
"&description=" + WWW.EscapeURL(description) +
"&redirect_uri=" + WWW.EscapeURL(redirectUri));
}//facebook share end
if(GUI.Button(new Rect(Screen.width/2,(Screen.height/2-30),80,20), "Share")){
print("Share");
share("http://www.halilcosgun.com","https://24.media.tumblr.com/avatar_ce3a5b939737_64.png","Facebook skor paylaşma denemesi " + score,"Skor da mı paylaşmıyah?","oyun çok yakında!","http://facebook.com");
}
I tried to write many adresses (many many configurations) intead of "http://facebook.com", but I can't find the true one.
If you know the solution, can you halp me please?
I would like to thank you for your interest.
there must me an invalid parameter that you have provided . try to find it out and make the change it will solve your issue
try the share with first s in caps example
Share("http://www.halilcosgun.com","https://24.media.tumblr.com/avatar_ce3a5b939737_64.png","Facebook skor paylaşma denemesi " + score,"Skor da mı paylaşmıyah?","oyun çok yakında!","http://facebook.com");
}
I followed the instructions at http://dev.sygic.com/documentation/custom-url-schema/ & http://help.sygic.com/entries/22207668-Developers-Only-Sygic-implementation-to-your-app-Android-SDK-iPhone-SDK-Url-Handler-
I am passing the coordinates to Sygic 12.991030334592057 as latitude and 77.80791163444519 as longitude.
Another com.sygic.aura://coordinate|12.9138|77.6680|drive
However Sygic says 'The coordinates are outside the map.'
String str = "http://com.sygic.aura/coordinate|" + latitude + "|"
+ longitude + "|" + type.toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
I also tried
String str = "com.sygic.aura://coordinate|" + latitude + "|"
+ longitude + "|" + type.toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
EDIT:
The type is enum. type.toString shows drive as the string.
What am I doing wrong?
Got the same problem. As enli was saying, the order of the lat,lon params is the opposite. This code worked for me:
String str = "com.sygic.aura://coordinate|" + lon + "|" + lat + "|" + type.toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
in my phone, this example call launched sygic and started navigation:
com.sygic.aura://coordinate|-3.588678|37.176278|drive
Hope it helps
There is nothing wrong with your code. Have you made sure that those values of longitude and latitude are correct? With which application you got those co-ordinates?
I was working on the same code today and it seems that I had used longitude at the place of latitude and vice versa. Try interchanging the co-ordinates. That worked for me when I was in the same boat as yours. If that is not the case, make sure that you have Sygic maps for that location by manually navigating to that location by navigating to that location from Menu > Navigate to... > GPS coordinates.
First of all I'm a complete noob to android. Going step by step on my first app and facing some problems.
I can get my location in terms of Lat and Lon and now i have to save it to file and able to read the file to compare location in future. Could anybody please help me out on this can be done.
Following is my INCORRECT CODE
public void saveCurrentLocation(Location location){
SharedPreferences prefs = this.getSharedPreferences("com.example.mylocation", Context.MODE_PRIVATE);
String currentLat = "com.example.mylocation.location";
String now = prefs.getString(currentLat, location.getLatitude());
}
Error shown is that location.getLatitude is a double and cannot be saved to string (quite obvious but not sure how to change it)
Thanks
location.getLatitude() + "";
In Java, the + operator is overloaded to concatenate Strings. If you add "" to anything, it will be automatically cast to String.
If you want to store the result of location.getLatitude() in your sharedpreferences try converting the double to a String:
String.valueOf(location.getLatitude())
I construct a URL with the following bit of code:
String login = rootActivity.getString(R.string.url_authentication);
login = login + "user=" + mySharedPreferences.getString("username", "invalid") + "&" + "key=" + mySharedPreferences.getString("key", "invalid");
login = login.toLowerCase(Locale.US);
System.out.println("Logging in at " + login);
new HttpConnection(handler).get(login);
The URL is valid, as far as I can see visually, but the HttpConnection fails because there's an illegal character in the URL at the index of the ampersand. What really flummoxes me is, the app has between 1,000 and 5,000 installs, and we have a total of two reports of this over the past year – both from American users using Samsung devices, so I doubt it's a character encoding issue.
Don't forget to urlEncode your parameters.
login = login + "user=" + URLEncoder.encode( mySharedPreferences.getString("username", "invalid") ) + "&" + "key=" + URLEncoder.encode( mySharedPreferences.getString("key", "invalid") );
Don't know what login is, but is there a question mark on the end of it? If you're don't something like www.example.comuser="something"&key="somethingElse" then that won't work.
Having a raw & (amplisand) will lead to an error, you should encode your special characters.
Do this:
String login = URLEncoder.encode(login);
http://developer.android.com/reference/java/net/URLEncoder.html#encode(java.lang.String)
friend's,
I am working in Facebook,here i need to change the image url value string has dynamic one,
here my code
intent
.putExtra(
"attachment",
"{\"name\":\""
+ Html.fromHtml(title)
+ "\",\"href\":\""
+ Html.fromHtml(url_val)
+ "\",\"description\":\""
+ Html.fromHtml(desc_val)
+ "\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.naicu.edu/imgLib/20070913_small_seal.jpg\",\"href\":\"http://alumni.brown.edu/\"}]}");
this.startActivityForResult(intent, MESSAGEPUBLISHED);
here image source given in code has static,but i need to assign an simple string variable in the place of double quoted image url,for example
i want to place string temp_url in the place of **src\":\"http://www.naicu.edu/imgLib/20070913_small_seal.jpg**,how can i get it.
Thanks in advance.