Showing location on google map by passing area name in android [closed] - android

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to show a Google map v2 in my android app, I want to get city name on Google map V2. As i enter city name in edittext control. I have one EditText, if i enter the area name or city name in EditText, the map should show the passing area name into my google map.I am using Google Map v2.Any help will be appreciated.
This is my code on button search click.
btSearch.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try {
Geocoder geocoder = new Geocoder(CreateReminderActivity.this);
List<Address> addresses;
String areaname = edLocation.getText().toString();
addresses = geocoder.getFromLocationName(areaname, 1);
if(addresses.size() > 0) {
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
insLat = latitude;
insLong = longitude;
String statename = addresses.get(0).getAdminArea();
googleMap.addMarker(new MarkerOptions()
.title(areaname)
.snippet("SNIPPET")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(latitude, longitude)));
LatLng latLng = new LatLng(latitude, longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10));
Toast.makeText(getApplicationContext(), statename, 20).show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

Have you checked https://developers.google.com/places/documentation/search ?
You seem to be asking a very basic question.
Check this: How to Search in Google Map Api V2 Android?

You can use Geocoder for this purpose.
try {
Geocoder geocoder = new Geocoder(this);
List<Address> addresses;
addresses = geocoder.getFromLocationName("PLACE_NAME", 1);
if(addresses.size() > 0) {
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
map.addMarker(new MarkerOptions()
.title("TITLE")
.snippet("SNIPPET")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(latitude, longitude)));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Related

all areas latitude and longitude between route defined

I am working on google map app.when i define a route For example from city one to city two ..then how can i get the latitude and longitude of all places coming between city one and city two.
destinationid= (EditText) findViewById(R.id.destinationid);
String clocation = destinationid.getText().toString();
List<Address> addressList=null;
if(clocation!= null || clocation!="")
{
Geocoder geocoder=new Geocoder(this);
try {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q="+clocation+""));
startActivity(intent);
addressList= geocoder.getFromLocationName(clocation,1);
}
catch (IOException e)
{
e.printStackTrace();
}
Address address= addressList.get(0);
LatLng latLng=new LatLng(address.getLatitude(),address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("Current Location "));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.addMarker(new MarkerOptions().position(latLng).title("Current Location "));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.0f));
mMap.animateCamera(CameraUpdateFactory.zoomIn()); mMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null); CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng)
.zoom(15)
.bearing(150)
.tilt(70)
.build();
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mMap.setTrafficEnabled(true);
}'
To answer your first question in comment above,
1] to show any particular point B on your route you can use markers, this is a feature of google maps API, more details about this you can find here.
2] to check anyone is in your radius you can use Geo fence API. you can find more details here.

place markers stores(pirtucular store name) with google maps in android

Hi I want place markers on all shoppers stop stores which are near to user current location. I am using following code
currently I am getting only 2 locations, I want set some radius and want to display all the stores also.
private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {
#Override
protected List<Address> doInBackground(String... locationName) {
// Creating an instance of Geocoder class
Geocoder geocoder = new Geocoder(getBaseContext());
List<Address> addresses = null;
try {
// Getting a maximum of 3 Address that matches the input text
addresses = geocoder.getFromLocationName(locationName[0], 10);
} catch (IOException e) {
e.printStackTrace();
}
return addresses;
}
#Override
protected void onPostExecute(List<Address> addresses) {
if(addresses==null || addresses.size()==0){
Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
}
// Clears all the existing markers on the map
googleMap.clear();
// Adding Markers on Google Map for each matching address
for(int i=0;i<addresses.size();i++){
Address address = (Address) addresses.get(i);
// Creating an instance of GeoPoint, to display in Google Map
latLng = new LatLng(address.getLatitude(), address.getLongitude());
String addressText = String.format("%s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getCountryName());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(addressText);
googleMap.addMarker(markerOptions);
// Locate the first location
if(i==0)
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
}
but unable to get relevant results. Help me.
You should have a look at nearby search of Places API web service.
To make your life easier you can also use the Java Client for Google Maps Services located at github:
https://github.com/googlemaps/google-maps-services-java
Follow documentation of the Java Client library and you should be able to search nearby places for given location and radius.
I hope this helps!

How to make a marker to a location in Google Maps Activity?

I'm making an app with a Google Maps Activity and I want to place a marker there. How do I set a marker to a location, for example the White House, so that it opens up the info page in google maps when you press the maps button in the right corner? My code:
LatLng latLng = new LatLng(38.897677, -77.036531);
mMap.addMarker(new MarkerOptions().position(latLng).title("The White House"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
Here is answer of your question what I am perceived that actually you wants to implement a click Listener.
There are two ways to do it
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener( ) {
#Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(StoreMap.this, "Info window clicked", Toast.LENGTH_SHORT).show();
}
or use this one if you are intend to direct user just by clicking on marker.
GoogleMap.setOnMarkerClickListener(OnMarkerClickListener)
just implement as similar as above
more details
So you want your app to search for places? Try Geocoding. Here's my super simplified search method:
public void onSearch(String searchLocation) {
mGoogleMap.clear();
List<Address> addressList = null;
Address address = null;
LatLng latLng = null;
Geocoder geocoder = new Geocoder(mContext);
try {
addressList = geocoder.getFromLocationName(searchLocation, 1);
} catch (IOException e) {
e.printStackTrace();
}
address = addressList.get(0);
latLng = new LatLng(address.getLatitude(), address.getLongitude());
mGoogleMap.addMarker(new MarkerOptions().position(latLng).title(searchLocation));
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}

Using Maps in Android

I have the address to certain location in terms of a string. However i want to convert this address to Lattitude and Longitude. So i used the code given below to convert into geopoint. But this geopoint is not getting added to the map. The map always shows the default map thats the entire world.
public GeoPoint getLocationFromAddress(String strAddress) {
Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;
try {
address = coder.getFromLocationName(strAddress, 5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
return p1;
} catch (IOException e) {
e.printStackTrace();
return p1;
}
}
Im new with maps and am not sure what Im doing wrong. Any suggestions?
Now that you know the latitude and longitude, you forgot to update the map to the specific location. You can do it like this:
int zoomNiveau = 15;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), zoomNiveau));
With this code, the map will go to the location of the address. But you need to create a Marker and add it to the map if you want a Marker.
More info about the markers: https://developers.google.com/maps/documentation/android/marker

Zoom in map different for city vs country android

I use below code to search on google map android
// An AsyncTask class for accessing the GeoCoding Web Service
private class GeocoderTask extends AsyncTask<String, Void, List<Address>>{
#Override
protected List<Address> doInBackground(String... locationName) {
// Creating an instance of Geocoder class
Log.d("bagibagi","doInBackground");
Geocoder geocoder = new Geocoder(getBaseContext());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocationName(locationName[0], 1);
} catch (IOException e) {
e.printStackTrace();
}
return addresses;
}
#Override
protected void onPostExecute(List<Address> addresses) {
Log.d("bagibagi","onPostExecute");
search = "";
if(addresses==null || addresses.size()==0){
Toast.makeText(getBaseContext(), "No Location found OR you use this several time", Toast.LENGTH_SHORT).show();
}
else
{
// Adding Markers on Google Map for each matching address
for(int i=0;i<addresses.size();i++){
Address address = (Address) addresses.get(i);
// Creating an instance of GeoPoint, to display in Google Map
latLng = new LatLng(address.getLatitude(), address.getLongitude());
String addressText = String.format("%s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getCountryName());
markerOptions = new MarkerOptions();
//markerOptions.icon(icon);
markerOptions.position(latLng);
markerOptions.title(addressText);
//map.addMarker(markerOptions);
Toast.makeText(getApplicationContext(), addressText, 1).show();
// Locate the first location
if(i==0){
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng) // Sets the center of the map to Mountain View
.zoom(13)
// Sets the zoom
//.bearing(90) // Sets the orientation of the camera to east
//.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
}
}
}
how i can change .zoom(13) for a city search or a Country name search.
for example when user search a country map must zoom smaller than search a city.
below image show you thing that i want.
You can use Google Places API to obtain the Viewport of particular place.
Make request to this url: http://maps.googleapis.com/maps/api/geocode/json?address=YOUR-COUNTRY-OR-CITY&sensor=true
In the JSON response you will find the following keys:
geometry:{
bounds:{
northeast:{
lat:40.501368,
lng:-79.8657231
},
southwest:{
lat:40.3613689,
lng:-80.0952779
}
},
location:{
lat:40.44062479999999,
lng:-79.9958864
},
location_type:"APPROXIMATE",
viewport:{
northeast:{
lat:40.501368,
lng:-79.8657231
},
southwest:{
lat:40.3613689,
lng:-80.0952779
}
}
}
Either go for "geometry" key data or "viewport"
Create new LatLngBounds (LatLng southwestParsedCoordinate, LatLng northeastParsedCoordinate) object and move the camera to the that bound object
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10);

Categories

Resources