Google Maps advanced features in a MapActivity (Google Maps API) - android

I wanted to load a custom KML file on the map. I chose the simple way:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, url);
And it works well, but obviously I can't control various features like custom icons for overlay items, or the popup "Loading myKml.kml..." that shows everytime I start it, etc.
First question:
Aren't there any parameters to setup when I start a Google Maps Intent, to tweak my map? I can't find anything on the documentation.
So I was thinking about using the Google Maps API for my app. Well, I've managed to load my KML file parsing it with a SAX parser and creating a custom overlay for my map.
It works, but there is a great problem:
The placemarks aren't loaded dynamically in relation to my position. They are loaded from the start to the end, and are shown on the map 100 at time.
So it was going to be harder than I thought, because I'll have to get my position from the GPS and calculate only the nearest points and draw them on the map.
Second question:
Does exist a built-in function to show only near-to-me placemarks on the map?
Thank you, guys.

2nd question. No. Have a look at LocationManager.addProximityAlert(double latitude, double longitude, float radius, long expiration, PendingIntent intent).

Related

how to set alarm to osmdroid when closer to boundary

I am developing an application in which I need to use maps offline. I'm using osmdroid and osmbonuspack
I have implemented code to display user's current location. And display boundary by importing KML content.
How can I set alarm to notify user, when user come closer(about 50m-100m) to that boundary?Click to see the image
You can buffer the area by (50m, 100m) and use LocationManager #addProximityAlert() to set a trigger.

How to display boundary of an area using Google maps API v2 for Android

I am writing an application where I need to mark the boundary of an area with certain colour, for example, if I search for "London", it should show a coloured boundary of London on the map. If I search for "UK", it should display coloured boundary of the UK.
This works well with Google maps on the web browser such that if I search for "Essex" on Google maps, it shows a red-dotted boundary of Essex.
Is there anyway I can get this feature on my Android app using Google maps API v2?
I found a couple of links below:
how to change the color of a particular area on Google map api v2 in android
Is it possible to get cities polygonal boundaries like in Google Maps?
It looks like I need boundary data in the form of polygon data points and use it as marker to display boundary. There are different websites which provide this polygon data but not sure how to use this data. It looks complicated, I think there has to be a simpler way to implement it.
EDIT:
Just to update on how i ended up doing it. I had to get Lat/Lng data from free boundary data providers and draw it manually using
PolylineOptions options = new PolylineOptions();
for(LatLng latLng: getLatLngList()) {
options.add(latLng);
}
options.color(Color.RED);
options.width(POLYLINE_WIDTH);
map.addPolyline(options);
I had to draw London boroughs and I got boundary data from:
https://www.google.com/fusiontables/DataSource?docid=1WlXk5RnE3oVRtrsqnm48V75pfN66Do0nbIw2xX8
Thanks
Here is a REST API for this , works well with google maps on andriod.
UK Postal-Unit(ex. ZE1 0AE) ,Sector,District, City, and wards boundaries in GeoJson
https://www.mashape.com/vanitysoft/uk-boundaries-io

Unable to display route on Osmdroid map

I am unable to get a route displayed on a Osmdroid map displayed on an Android 4.3 smartphone.
I am using osmbonuspack v4.4 jar and osmdroid-android v4.1 jar. I have overriden/copied OSRMRoadManager to CarRouteManager so that it makes use of the java.net.HttpURLConnection instead of the Apache HTTPConnection. With Apache HTTPConnection I don't get any route information back but with the java.net.HttpURLConnection I get route information back. The road has a mStatus of STATUS_OK and I can see the various parts of the route when I debug my code.
The route drawing function is the following:
public void DrawDirection(Road road)
{
if (road.mStatus == Road.STATUS_OK)
{
current_route = CarRouteManager.buildRoadOverlay(road, Color.BLUE, 3, this);
current_route.addPoint(user_point);
current_route.addPoint(clicked_location);
map_view.getOverlays().add(current_route);
map_view.invalidate();
}
}
With the above code I just get two polylines displayed on the map, one which traces straight from the GeoPoint user_point(starting point) to the GeoPoint clicked_location (destination). The other polyline traces to the right-bottom of the screen and off the current map area that is visible, when I zoom out to the world map it extends all the way off the edge of the map at Antartica.
When I remove the two lines
current_route.addPoint(user_point);
and
current_route.addPoint(clicked_location);
then there are no polylines drawn on the map. I have debugged the contents of current_route (which is of type PathOverlay) and the points in the mPoints array are valid GeoPoints, i.e. not null. When I map these GeoPoints onto the Google map at https://maps.google.com/ then it shows that these GeoPoints are valid locations on the roads/route between GeoPoint user_point(starting point) and GeoPoint clicked_location (destination).
Has anybody suffered the same affect and managed to solve it?
I would recommend you to:
get rid of your CarRouteManager stuff
just follow closely the OSMBonusPack tutorial
taking care about the "Important Note" at the very beginning of the Tutorials.
If you still have issues, have a look here:
RoadManager for osmdroid error
Only when you will have a better understanding of the inner behaviour of the lib, you will be able to implement your own RouteManager (if really needed).

How to Implement Google Map Tile Provider in android?

I am working on custom map app and i want to use google map tiles for background ? There is one class TileProvider in api but i don't know how to initialize it every time i try it goes something like this ?
TileProvider tileProvider=new TileProvider() {
#Override
public Tile getTile(int i, int i2, int i3) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
};
how to override getTile function to get tiles from google map server?
Any example will be appreciated ?I know getTile function need x,y and zoom value to return tile.
So quick answer is that you can get the Google Map tiles from the following URL:
http://mt1.google.com/vt/lyrs={t}&x={x}&y={y}&z={z}
Where {t} is the type of map (satellite, road, hybrid, etc) and the other attributes are specifying the coordinates and zoom level.
The possible values for {t} are as follows:
Default - m
Roads only - h
Roads simplified - r
Satellite - s
Satellite hybrid - y
Terrain - t
Terrain hybrid - p
That being said you do want to make sure what you're doing is NOT a violation of the terms & services. Specifically Google WILL allow you to cache their tiles provided that you are doing so ONLY in order to improve performance and that you delete their tiles at least every 30 days, and finally you don't pull down their tiles in an attempt to make your own mapping service.
You may want to read the Google Maps Terms of Service - https://developers.google.com/maps/terms - specifically section 10.1.1

Calculate the area covered by a polygon in a google map in an Android App

I've got a series of Location / GeoPoint objects that form a polygon in my Android app. I wonder if there's any way to calculate the area covered by it.
So far I'm thinking about setting up a web service that, when posted the list of coordinates, uses the JS Google Maps API v3 to calculate the area. But there might be a way of doing this easily with some feature from Android I don't know about, natively.
Thanks in advance for your help!
A method doing this is posted in following answer:
https://stackoverflow.com/a/16210785/891479
This is based on following formula:
http://mathworld.wolfram.com/PolygonArea.html
http://en.wikipedia.org/wiki/Polygon
Principle of plolygon area calculation using this formula:
http://maruzar.blogspot.com/2011/12/irregular-and-regular-polygon-area-by.html
If you want to do it yourself, the way to calculate any polygn area knowing the corrdinates is explained in Polygon.
You can find a more comprehensive explanation in How to Calculate the Area of a Polygon under the topic Irregular Polygons
Just in case it helps someone, there is a very good answer in this thread:
Calculate the area of a polygon drawn on google maps in an Android application
The answer from Marian Paździoch:
There's already a library for that.
import com.google.maps.android.SphericalUtil;
//...
List<LatLng> latLngs = new ArrayList<>();
latLngs.add(new LatLng(51.893728, -8.491865));
latLngs.add(new LatLng(51.893550, -8.492479));
latLngs.add(new LatLng(51.893216, -8.492224));
latLngs.add(new LatLng(51.893404, -8.491598));
Log.i(TAG, "computeArea " + SphericalUtil.computeArea(latLngs));

Categories

Resources