Creating Google Location URL by using latitude & longitude information - android

I have a code where I'm retrieving latitude and longitude information. I'm interested to show that information on map. I would like to create a link for Google map with retrieved "longitude" and "latitude" information. I am using Linkify for this as follows:
**** Java Code**:
String text = "maps.google.com/?q=latitude,longitude";
TextView label = (TextView)findViewById(R.id.textView);
label.setText(text);
Pattern pattern = Pattern.compile("maps.google.com");
Linkify.addLinks(label, pattern, "http://");
But this code is not working. Can someone help me with code?
I am getting something like following. My longitude and latitude are not getting linked with rest of the url.

you may use below code for displaying map
String url = "geo:" + sLatitude + "," + sLongitude +"?z=22&q="+sLatitude + "," + sLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
above code shows map using google map application installed in your phone, it also mark the location with zoom level of 22. No google map api key required
Hope this will help...

You may also use the android:autoLink attribute of the TextView to convert the string into links. It controls whether links such as urls and email addresses are automatically found and converted to clickable links.
For example, you may add it in your layout (.xml) file.
<TextView
android:id="#+id/google_map_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web" />
It will automatically convert the text into links for you. Hope it helps you :)

Related

App crashing while using Google Places API with textsearch query and passing location name with Spaces

Code to create URL:
EditText editText = (EditText) findViewById(R.id.editText);
String Destin = editText.getText().toString();
StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/textsearch/json?");
//googlePlacesUrl.append(name);
googlePlacesUrl.append("key=myKey&query=");
googlePlacesUrl.append(name);
=========================
Logs on Fail:
java.io.FileNotFoundException: https://maps.googleapis.com/maps/api/place/textsearch/json?key=myKey&query=Place_name street
Also,succefussly getting location for:name=place_name i.e. with no spaces
https://maps.googleapis.com/maps/api/place/textsearch/json?key=myKey&query=Place_name
Use UrlEncoder.encode(name) to encode the query string. This will replace the space with %20.
(see also: https://stackoverflow.com/a/3286128/2994)
Download Sample project of Google Place API from
Google Place API Sample
...Jalsa kar bhai
Space is not work in url while execute request whether it is get or post.
If url contain space then it is necessary to encode space in unicode then and only it works.
For that
If Place Name has space then it should be replace with '%20'
Eg. Place Name : united kingdom then
placeName = etPlaceName.getTExt().toString();
placeName = placeName.replace(" ","%20");
Use this place name in url to get result...........

Uri builder - why does it delete part of a string?

This question is under the context of Android.
So according to Google's documentations this is how we should send a query to a maps app:
https://developer.android.com/guide/components/intents-common.html#Maps
Or in other words,send it a URI of geo:0,0?q=my+street+address
when we wish to go to my street address
However, if I apply this code:
final String GEO_LOCATION="geo:0,0?";
final String QUERY_PARAM="q";
Uri builtUri = Uri.parse(GEO_LOCATION).buildUpon().appendQueryParameter(QUERY_PARAM,location).build();
builtUri will actually not have 0,0 eg if you check out its String value (to String or debug mode),
the value is geo:?q=.... without 0,0.
While my maps app (Google maps) works perfectly fine without the 0,0, it will be amazing for me to understand what's going on! Why is the 0,0 being deleted? Any way for me to keep it if i want it to be sent with the intention?
geo URIs don't really follow the full rules for URI syntax. geo URIs are "opaque" in that everything after "geo:" is essentially free of the usual URI spec (it can be whatever they want). In Google's case, they choose to use parameters that look like query strings, but they are not query strings in the sense of the URI spec. I know, it's weird.
If you want to build an android Uri from an opaque geo URI using as much "proper" code as possible, you could do it like this:
float lat = ...
float lon = ...
String addr = URLEncoder.encode("my address", "UTF-8");
java.net.URI(
"geo",
"" + lat + "," + lon + "?q=" + addr,
null);

Sending clickable gps long/lat via SMS

In my app, I'm getting the user's location using this bit of code:
locationText = location.getLatitude() + "," + location.getLongitude();
...and I'm sending it to another user via SMS using this bit:
smsManager.sendTextMessage(phoneNo, null, locationText, null, null);
... When the other user receives the txt, they get it as "longitude, latitude". Either one is clickable but how would I format the string so when its received, it's clickable as a combined long/lat? I've tried removing the comma (,) but then none of it is clickable. Google searching yielded only how to search using long/lat in google maps. Any and all help is greatly appreciated.
Thank you
Form url like following url link,
http://maps.google.com/maps?q=lat,lng

Show a geo location using webview

I want to show a particular geo location on google maps. I can't use mapview / mapactivity.
Also I can't use action view intent
Can I use webview for this?
Open a url like this should work:
webView.loadUrl("http://maps.google.com/maps?q=47.404376,8.601478");
Replace 47.404376,8.601478 with your lat / long. Works in the browser, I guess on a mobile device it will open a mobile version of Google Maps.
Check out google Static Map API
https://developers.google.com/maps/documentation/staticmaps/?hl=nl
You have to construct an url that displays a static image of a map (possible markers) of your location.
you can then download it and display it in an imageview.
String latitude= "45.838211";
String longitude = "9.334661";
String url = "http://maps.google.com/maps/api/staticmap?center=" + latitude + "," + longitude+ "&zoom=10&size=400x400&sensor=false"

how to place geopoints on the image as map in android

hi this raju iam new to android. i created a small project in that project i displayed a image as map with custom view.
I have latitude and longitude point then how to show geopoints on image by using my latitude and longitude points please anyone help me.
if any one knows please provide some samples.
Hope this will help you GoogleMap in Android
There you go.
String getMapURL = "http://maps.googleapis.com/maps/api/staticmap?zoom=18&size=560x240" +
"&markers=size:mid|color:red|"
+ yourLatitude
+ ","
+ yourLongitude
+ "&sensor=false";
URL imgValue = new URL(getMapURL);
Bitmap userIcon = BitmapFactory.decodeStream(imgValue.openConnection().getInputStream());
ImageView imgMapInImage = (ImageView) findViewById(R.id.imgMapInImage);
imgMapInImage.setImageBitmap(userIcon);
Customize the rest of the parameters such as the width and height attributes in the getMapURL. My example uses the dimensions of 560*240. Use your dimensions. Also change the zoom, the pin size and colors to your liking.
Hope this helps.
EDIT: this example uses the Google Maps Static API. For more customization options, refer to this URL here: https://developers.google.com/maps/documentation/staticmaps/

Categories

Resources