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"
Related
On iOS, when we have a location's latitude and longitude, we can use MKMapSnapshotter to create an image. How to achieve this on Android?
In the screenshot below from an iOS app, a snapshot of the map can be created with a latitude and a longitude.
You can use "google static map" to get an image with location by coordinates.
You can load the generated image by creating a URL request, for example:
String url = "http://maps.google.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=15&size=300x300&sensor=false&key=YOUR_API_KEY"
Furthermore, you can dive into the documentation of static maps.
https://developers.google.com/maps/documentation/maps-static/overview
I am currently using Google static map API for an Android application. For Android application it gives me the correct image but when I use the same url in a browser it gives me a image of elsewhere.
My URL:
String url="https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&maptype=roadmap\n" +
"&markers=color:blue%7Clabel:S%7C6.972491, 79.917473\n"
+"&markers=color:green%7Clabel:G%7C6.962225, 79.894642\n" +
"&markers=color:green%7Clabel:G%7C6.951713, 79.917323\n"+
"&markers=color:red%7Clabel:C%7C6.912690, 79.908225\n" +
"&path=color:0x000000|weight:3|6.972491, 79.917473|6.962225, 79.894642|6.951713, 79.917323|6.912690, 79.908225\n"+
"&key=key";
Image I received:
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);
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 :)
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/