I'm a beginner in the field of android and currently working on a cab app . In this app I need to implement Map and directions API, I went through couple of tutorials and got several APIs but i dont know how to draw the returned data on the map so guys please help.. need some guidance. Thank you
For the moment i've extracted the latlng of source and destination and have created a seperate MapActivity for showing directions.
Google Directions API gives you a polyline (a list of LatLng points to draw a nice curvy line) of the returned route in an encoded format in "overview_polyline" and "polyline" fields in the JSON it returns.
By decoding this data you can create a Polyline object which is then drawn on the GoogleMap. Writing your own decoder isn't too difficult, but there's also android-maps-utils library that contains a method for this and many other fancy things you might want to use on Google Maps related things.
An example use of this library would be something like
GoogleMap map = ...;
String encodedPolyline = readFromJson();
Polyline line = map.addPolyline(new PolylineOptions()
.addAll(PolyUtil.decode(encodedPolyline))
.width(5)
.color(Color.RED));
Related
I am using google direction API to generate the Polygon. I have also used below methods of map utils but not get desired solution
PolyUtil.isLocationOnEdge(pbmLocation,poly,false)
PolyUtil.containsLocation(pbmLocation,poly,false)
PolyUtil.distanceToLine(pbmLocation, startLocation, destLocation)
I would like to use google map API to get a map canvas to put objects on it, but not showing the map, by using the maptype NONE.
Am I allowed to do that in an Android app using v2 and distribute it?
This is what I want to do:
#Override
public void onMapReady(GoogleMap map) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(-18.142, 178.431), 2));
// Other supported types include: MAP_TYPE_NORMAL,
// MAP_TYPE_TERRAIN, MAP_TYPE_HYBRID and MAP_TYPE_SATELLITE
map.setMapType(GoogleMap.MAP_TYPE_NONE);
}
I want to set map.setMapType(GoogleMap.MAP_TYPE_NONE); and then add various markers to the map, including my current position
Added a picture to show what I want to achieve.
As mentioned in Google documentation it's forbidden. More over - From what you are saying it seems that you want use gmaps capabilities to get data and calculations but actually display some thing else. I really don't think it's good idea. However - if the issue is making geo calculations, consider to use 3'rd party open source libs for this. For example http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula-java/
So basically i want to show the multiple locations of the office on google map within android application. And also wanted the company’s logo as the marker on map.
I dont have any idea how to do this.
Any help would be great for me ..
sorry for the bad english
to get started on google maps you need to read the documentation here, https://developers.google.com/maps/documentation/android/intro. After you complete the tutorial, you only need to add a mapFragment to the xml of the screen.
For setting up markers you need to get the mapFragment in the Activity.java:
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
and then set up a new marker:
map.addMarker(new MarkerOptions().position(MY_HOME).title("This is my home"));
MY_HOME contains a LatLng object with the latitud and longitud of the location.
I'm developing a android application with google maps v2 that draw polygons on the google maps. But now i have to identify a click on a certain polygon and popup a window.
I found this useful library on github
This library has the method containsLocation implemented. This method receives a LatLng (from click on the map) and a List (the polygon). This is fine but if i have 1 million polygon in the map i cant iterate all and test if a certain LatLng belongs to a certain Polygon. I remember that i can use a quadtree to get more performance and this library also implements a quadtree but it uses point. What is the best way of doing this? May i have to reimplement this quadtree for a quadtree of LatLng ? Or in each click i have to convert this click to a point and search on a point quadtree?
Regards
you cannot use a Point- Quadtree, you need an Object-Quadtree for your Polygons. An object quadree uses the bounding box of the polygon or any object for adding into the tree.
you dont need to consider latLong, use x,y with x= longitude, and y = Latitude.
Consider reading Hanan Sammet: Foundations of multidimensional data structures.
I think you need to implement a quadtree that stores the polygons, then query the tree to see which polygon (if any) contains the LatLng. If you search around I'm sure you can find a decent implementation.
Im developing a map app in which gps detects my current location and places a marker.Using spinner I get nearby places based on category.What I need is,When I longclick the marker of spinner,Using intent it should show the step by Step navigation instructions in a new page also it should draw route ie polyline from my location to the touched location.
I used http://wptrafficanalyzer.in/blog/showing-nearby-places-and-place-details-using-google-places-api-and-google-maps-android-api-v2/ code for abvove purpose.
Please Help..Thanks in advance.
You can take a look at this blog post I wrote on drawing the navigation on the map:
Google Maps V2 for Android: Draw Driving Direction on Map
For adding the Step by Step navigation I guess you would need to change the parsing method a bit in order to get this info from the JSON file you receive.