How do I create a new activity for each city? - android

Forgive me for being new to android app building.
My plan is to build an app that would take a city and open a new activity for it. The problem is I really don't know how to go about that. My plan would be very similar to how the app yik yak does it where you go put a marker in a certain area and it brings you to the activity for that location. I believe yik yak only shows the ones that are close to you but my plan was to take you to an activity for that location. Is that possible to do it that way or should I take yik yak's route on it and only show things that are within a certain radius of you?
Where can I get started on learning how to do that?

First, you need to choose a provider for your maps.
I would say google map is a good start as you suggested in the tag, but beware, it might not be available on some Chinese devices without play services.
You can follow the documentation here for a quick start
https://developers.google.com/maps/documentation/android/
Regarding the number of pins you want to put on your map, I see no problem to display a lot of them, you just have to group markers as the user zooms out, so you don't have 10 pins overlapping themselves.
So if in a quite zoomed state, the user clicks a group of markers, you can display a dialog to choose the city.
If the user zooms in a lot and clicks a particular pin, then you can start an activity.
Your main concern is listening for a zoom level change, like that:
mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
private float currentZoom = -1;
#Override
public void onCameraChange(CameraPosition pos) {
if (pos.zoom != currentZoom){
currentZoom = pos.zoom;
// do you action here
}
}
});
Credits: https://stackoverflow.com/a/15046761/689710
Then, you can create a Map of Lists, the keys of the map will be the a custom lat / long object. Let's call it Pin. Pin provides it a custom isCloseTo method (taking a zoomlevel in params, and an other Pin object).
For each city you want to add on the map
For each key in the map
If the Pin object of your city isCloseTo the Pin key of the map
Add it to the list for that key
Else
Add a new Map entry with you city Pin as key and a list with your city as value
You Pin.isCloseTo method will be somehow similar to that:
https://stackoverflow.com/a/18170277/689710
Returning true or false according to "dist" return and your zoom level.
When you processed all your cities, you can browse the map and create a marker for each Pin key.
In a zoomed in state, you will have a Map with lists containing only one item, but i don't think it's much a problem.

You know yik yak is not starting a new activity when the place on the map is clicked. It rather updates the data underneath it when a new place is clicked. I think what you mean is you want to refresh/change the data displayed when a new city on google maps is clicked?

Related

Would it possible to implement a button to the approach I'm taking to display information in a Google Maps marker in Android?

I'm creating a small app that will help a user find a sports club. I'm currently creating a club coordinate variable in the MapsActivity.java file like so:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng lansdowneRFC = new LatLng(53.3334103,-6.2201649);
// Adds location to the map (includes a small bit of info about the club)
mMap.addMarker(new MarkerOptions().position(lansdowneRFC).title("Lansdowne RFC").snippet("Aviva Stadium, 62 Lansdowne Rd,"));
}
This produces the following result
I'm trying to add a button to the information box that will bring the user to another activity (The activity will be a sign up form so they can join the club). Considering the approach I'm using is it possible to implement a button or will I have to approach it in another way? I've seen ideas like a custom popup window be suggested for this type of thing but how I implement that into a google maps marker instead of a button is where I'm hitting a brick wall. Any suggestions
You can set your own implementation of InfoWindowAdapter to your GoogleMap object with a call to setInfoWindowAdapter().
And in the adapter you can override getInfoContents() to return whatever view you want.
But the down side is the view that is shown is not a live view, it's an image of the view you created, and you can handle the click on it using a OnInfoWindowClickListener that you set on the GoogleMap object with setOnInfoWindowClickListener().
But that handles the click on the whole window, not just the button.
Another option is to know where your marker is at the screen and show a popup manually above it that has nothing to do with the map, but I would not recommend that approach, with Android's different device sizes and all, that could quickly get very ugly.

Android maps markers show on map only after zooming change

I made simple application where I get markers based on screen coordinates from the server. Problem is that markers doesn't appear on map immediately. User user must zoom in or zoom out only then marker is visible. Why is that? Is it possible to show marker as soon when marker data is downloaded from server? Or is it possible to somehow refresh map? I know that in previous version there was method map.invalidate() that is basically what I need to have now. Unfortunately this method is not available now.
I will add code snippet how my markers is added
#Override
protected void onPostExecute(ArrayList<MarkerItemData> markerItemData) {
super.onPostExecute(markerItemData);
if(markerItemData != null) {
mClusterManager.addItems(markerItemData);
}
}
It needs re-clustering again.
mClusterManager.addItems(markerItemData);
mClusterManager.cluster();
Because, when you add or remove an ClusterItem (MarkerItemData), it just performs the algorithm and calculates clusters. But does not render on map
Finally, ClusterManager listens onCameraIdle event(includes zoom events) and invokes cluster() method internally. This is the answer of user must zoom in or zoom out only then marker is visible.
From the javadoc here, you need to recluster your markers after adding them to your ClusterManager doing mClusterManager.cluster().

How to implement first person view in android google map?

In my android application i want to implement first person view. Please check following URL for first person View -
Google First Person View
I found one link which redirects to first person view please check -
Google Maps Navigation - Using Google Navigation in Android Application
But in it we don't have control over navigation view or first person view. It redirects to google's default first person view. I want to implement it manually. Means in which we can pass latitude and longitude dynamically(from Server)
Is there any way to implement first person view Pro-grammatically, in which we have command over view ?
Thanks in advance!
Don't know exactly, how to achieve that view, but you can do one thing, that is whatever orientation's value you are getting from your server or any gps device , pass it into bearing() method of CameraPosition and set tilt also, like following -
CameraPosition cameraPos = new CameraPosition.Builder().target(latlng)
.zoom(zoomvalue).bearing(orientation).tilt(tiltvalue).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), null);
by doing this your map will be rotate according to value of orientation. and if you pass value of orientation into rotation(orientation) method of marker then your marker will rotate according to value.
Hope it'll help you.

How to manage Markers well using google maps api v2 on android

I'm trying to implement app in which you can add your own marker which will be given a shutdown time. To do so I need to know how to manage my markers. Let's say I have array list of users with assigned unique ID.
private ArrayList<User> userList = new ArrayList<>();
Then I will create array list of markers which will contain information like Latitude, Longitude, Title, owner's ID and deadline.
private ArrayList<MyMarker> mMarkersArray = new ArrayList<MyMarker>();
Next whenever user will activate add marker method, new marker will be pushed to my list of markers. Ideologically everything seems nice and easy, furthermore creating new object looks like this:
Marker mMarker = mMap.addMarker(new MarkerOptions() (...) );
but when it comes to managing specific markers it seems like I'm missing something. There will be some trigger method which will check the deadline of all markers (or rather first one on the 'sorted by deadline' list) and then it should remove (not hide, because I think it would be inefficient from the memory point of view). How to achieve this? I can't add some custom variable like ID to markers (so I could then find the one I'm interested in) and I'm a bit lost.
There is a way to achieve this by clearing whole map and then rendering again all markers except the inactive, but as far as I'm concerned it's very inefficient and there has to be better solution.
If you want to remove a specific marker from the map, you can just call the remove(). method.
Sample code to remove a marker from MapView and HashMap:
for (Marker marker : hm.keySet()) {
if (hm.get(marker).equals(deadline)) {
marker.remove();
hm.remove(marker);
}
}
You dont need to clear the entire MapView, if you just call remove() method on specific marker.

Android application which allows location selection through google maps

I am trying to make an application which allows the user to select a location on google map(on the press of a button). It is not related to his current position. He can select any position he wants(I was reading into markers, some help on that will be greatly appreciated). After he selects the location, I want that location to be saved in a string format in my application, so that I can do further work with it. I have searched around a lot, but can't seem to find any which allows the user to select his location through gmaps and save it, all through another application. Please help!
Assuming your map is called myMap, i think it should be something like this.
myMap.setOnMapLongClickListener(new OnMapLongClickListener(){
#Override
public void onMapLongClick(LatLng point) {
//TODO Handle your code.
//Add marker to map for clarity
myMap.addMarker(new MarkerOptions().position(point).title("My Marker"));
}
});

Categories

Resources