I am pretty much a novice at Android development, so please feel free to describe in very simple terms any advice you may give in response to my query.
I would like my application to start by displaying an Activity zoomed out to an extent that shows both my current location and that of a marker that I have placed on a map some distance from me.
I have successfully placed and displayed the remote marker the on the map and have found this class: LatLngBounds.Builder, which allows me to determine the bounds of all locations I am interested in, by supplying it the locations via its include method.
I obviously know the LatLng of my remote marker, but rather than going through the rigmarole of getting my current location using Google Play services and the location services API was wondering if, as my location has already been determined and is being displayed as the standard Google small blue circle, by virtue of me having set map.setMyLocationEnabled(true), whether my code has access to this ‘marker’. If it has, and I somehow know its ID, then could I not simply determine my location from [currentLocationBlueCircleMarker].getPosition()?
Thank you
There used to be a way to get a Location from a GoogleMap object, but it has been deprecated:
com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener
This interface is deprecated. use
com.google.android.gms.location.FusedLocationProviderApi instead.
FusedLocationProviderApi provides improved location finding and power
usage and is used by the "My Location" blue dot. See the
MyLocationDemoActivity in the sample applications folder for example
example code, or the Location Developer Guide.
So, you will need to use other means to get the current Location, though it's quite simple to get the current location using the FusedLocationProviderApi from Google Play Services.
For a complete example (targeting api-23 and up) see here: https://stackoverflow.com/a/34582595/4409409
For a complete example (targeting api-22 and down) see here:
https://stackoverflow.com/a/30255219/4409409
Related
I've been looking at the Places API from Google for this, but I don't know if this is the right direction to take. The project revolves around finding a list of places based on a specific location, other than the current location (for instance, what kind of restaurants are around your friend's house (based on longitude and latitude)). Most of what I've seen with the Places API involves using the user's current location. Is there a way to pass in a predetermined location? Or can I fool it into thinking that location is my current location?
I think still places is the best option for you, you have to really understand the api to get what you need from it. Look at how could you send a request to the places api with a given location (long, ltd) and it will return nearby places.
https://developers.google.com/maps/documentation/places/web-service/search-find-place#locationbias
I've been trying to open Google Maps (specifically on Android, but not necessarily) from a coordinates URL, such as
https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754
But when the map opens, I want it to show the location name such as "Tower Bridge". Not the coordinates 51.5055,-0.0754
I have tried something like
https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754&query_place_id=Tower+Bridge
with no luck. When maps opens it shows the coordinates, not the place name.
I am okay with either "injecting" the location name (something like https://....&location_name=Traitors+Gate), and/or with maps revealing the location name (reverse geocoding) from the coordinates.
Motivation: Coordinates are more accurate and less ambiguous than location names. For example, there is Jerusalem, OH and there is Jerusalem, Israel, which is half a world away. Or, "Palais de Louvre" which is just one building but one huge building over four streets, with multiple entrances. Coordinates solve those issues, but they are not "Human readable". You can't present "49.3697,0.8711" to a user and expect them to recognise the Omaha Beach.
Thanks
Unfortunately, the Google Maps URLs doesn't support this kind of sending labels. You should send a valid place ID value in order to get correct title of the place in Google Maps app.
You will need one additional step to do this. Execute reverse geocoding request for coordinate and get a place ID.
https://maps.googleapis.com/maps/api/geocode/json?latlng=51.5055%2C-0.0754&language=en&key=YOUR_API_KEY
This will return a place ID ChIJlRsEuUgDdkgRSM7ciIhVooM of Tower Bridge. Have a look at this example in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D51.5055%252C-0.0754
There is a Java client library for Google Maps API Web Services that you can find on GitHub:
https://github.com/googlemaps/google-maps-services-java
You can use this library to execute geocoding requests, alternatively you can also use Places API nearby search to get the nearest place. Note that web services require a different API key, because they don't support Android app restriction that you use in API key for Maps Android API.
Once you get a place ID value just create Google Maps URLs link. E.g.
https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754&query_place_id=ChIJlRsEuUgDdkgRSM7ciIhVooM
I hope this helps!
I want to make a android app using google maps.In this app I want to share my location to my friend like a request, Once he accepted my request he will get the route map to my location (previously I shared) and also I want to see his moving path towards my location. Can any one please suggest me how is possible to sharing locations.
I think the best way to control that sharing is using socket.IO
on the device you catch your position then emit your position to the server and on the server side you emit to other devices.
Hope helped you
For sharing locations and showing it on map, you need to do it in following steps
Read your location using android APIs.
Once he accepts your request, read his location and share it to your profile through some API to server & keep on updating location on every changed distance delta or at some time interval and share that too.
Now you have co ordinates of both locations. Use them to fill data to Google Maps API and load map in one of your activity. Whenever you will receive updated location of your friend from your server, update the map and draw path between them using google maps api.
For showing map to your location # your friends side, same thing needs to be done. If your location will also change then you will have to provide your updated location to server timely as mentioned in step 2
What if you send a geo: link to your friend? Like geo:62.0,-7.0 ? That should give the receiver a choice between all his geo-capable apps. Google Maps, OsmAnd, maybe some weather service...
i'm getting latitude and longitude of a location, I want to know the roads connecting to that location and whether it is land or water
I tried one google map api which is not helping to get the information i want.
http://maps.google.com/maps/api/geocode/json?latlng=40.7127,74.0059&sensor=true
Another SO answer pointed out two possible workarounds:
You can use Google Maps Reverse Geocoding . In result set you can determine whether it is water by checking types. In waters case the type is natural_feature. See more at this link http://code.google.com/apis/maps/documentation/geocoding/#Types.
You can detect waters/lands by pixels, by using Google Static Maps. But for this purpose you need to create http service.
You can use the Google Maps Geocoding API which does exactly that: http://code.google.com/intl/da-DK/apis/maps/documentation/geocoding Take a look at the "Reverse Geocoding" section
I was wondering how I can channel or simulate Google Maps just in the sense of a user types in a location in text, such as a restaurant name and a city name. Then Google suggests 5 or so places they have indexed, and presumably they know the GPS coordinates because Google then puts them on a map. I want to be able to use that feature- not the map, just getting the location.
My goal is for a user to type in a query, 5 options or so to be shown, and if they user chooses one of them, then the GPS coordinates, or a location object, is saved representing that place.
Ideally I could just send the query to Google and steal the results back to my app. Obviously building my own database of locations and an algorithm to suggest them is out of the question.
Thanks for the help and advice in advanced!
Note 1: To clarify, this does NOT involve the current position of the user/device.
Note 2: I looked at the Google Maps add-on API, but it looks like that is for a visual map, not the querying a location part. You are already supposed to know your location, and it will map it.
Use geocoder.getFromLocationName, you get back a list of Address objects, in those objects you will find all the information you need about the location.
To test this on the simulator you need an image with the Google APIs included. In a device should be fine if you have the market installed.