Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement search functionality for Google Map Api V2 Android?

I need to implement a search functionality for my Android Google Map Api V2 project and can't find any working example. I just need to enter a city name, press a "Search" button and then the map should move to the city and show a marker on it. Just like the Google Maps application does. Autocompletion should be nice though. I actully get to show the map, show some markers, etc, I just can't get to perform the search and see the results. Please help!

Thanks in advance

like image 880
Alejandro Casanova Avatar asked Feb 09 '14 18:02

Alejandro Casanova


People also ask

How to add Google Maps activity in Android project?

Make sure to select Maps Activity while creating a new Project. To generate the API key for Maps you may refer to How to Generate API Key for Using Google Maps in Android. After generating your API key for Google Maps. We have to add this key to our Project.

What can you do with the Google Maps Android API?

There are tons of things that you can do with the Google Maps Android API. When you feel comfortable with the basics, feel free to get explore the API and add new functionality to your app. If you incorporated Android Wear into your MapPlayground app, then head on over to the next step to learn about the Google Maps API for Android Wear.

How to add Google Maps API key to your project?

After generating your API key for Google Maps. We have to add this key to our Project. For adding this key in our app navigate to the values folder > google_maps_api.xml file and at line 23 you have to add your API key in the place of YOUR_API_KEY .

What is Google map layout for Android?

Google Map layouts for Android is based extensively on fragments. Instead of creating your own, the Google Maps API includes them with the majority of the backend done for you. As the developer, all you have to do is manage their lifecycle, layout, and interaction. I'll cover all of these topics below.


1 Answers

I just need to enter a city name, press a "Search" button and then the map should move to the city and show a marker on it. Just like the Google Maps application does.

So for that you have to make the functionality on Click of search in which you have to do as follows:

  • The city name entered by the user Will be sent to the google api - It will get back the lat-long to you.
  • You will use that lat-long to add marker as well as,
  • You will use that lat-long to animate the Gmaps Camara. That's it.
  • In this way you are able to fullfill your above requirement.
like image 55
Sagar Shah Avatar answered Oct 17 '22 00:10

Sagar Shah