I've developed a class that inherits from a View class and I want it to serve as a marker on a MapFragment/MapView from a Google Maps API v2. As I recall, such thing was possible in API v1 and even now it is possible on iOS. I'm looking for something like this:
MapView map = (MapView)findViewById(R.id.mapview);
CircleTimerView myTimer = new CircleTimerView(this);
LayoutParams lp = new LayoutParams(iv.getWidth(), iv.getHeight(), geoPoint, LayoutParams.BOTTOM);
map.addView(myTimer,lp);
My custom View is animated and it is a key feature of my app.
My question is: Is it possible for a current state of Google Maps API? Or should I try to obtain API v1 key and work with something that was deprecated?
Thanks in advance for your replies.
should I try to obtain API v1 key and work with something that was deprecated?
You cannot obtain new keys for API v1.
My custom View is animated and it is a key feature of my app.
You cannot have animated Marker icon unless you repeatedly change the icon using Marker.setIcon.
Is it possible for a current state of Google Maps API?
You can use a View as icon if you draw it into a Bitmap first.
This library from Chris Broadfoot can greatly help you with that task:
https://github.com/googlemaps/android-maps-utils
See this video for what the lib can do: http://www.youtube.com/watch?v=nb2X9IjjZpM
Or the new website: http://googlemaps.github.io/android-maps-utils/
in order to customize / use your own custom maker on google maps api v2 you could write the code as follows:
in onCreate declare the marker:
userIcon = R.drawable.red;
and then i used it where you need it, in my case i used it in a method:
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 100, null);
CameraUpdate center=
CameraUpdateFactory.newLatLng(lastLatLng);
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
theMap.moveCamera(center);
theMap.animateCamera(zoom);
hope this helped. good luck
i had the same issue these days and you should do the switch for v2 as you can do all the same stuff from v1 easier + many new features.
MapView has been replaced with the new GoogleMap-Objecttype.
A very detailed and decent Tutorial site can be found HERE!
Related
I need to display user inserted pins on the map that i will have in my application.
This pin needs to be visible to all the users using the app.
I have no clue how to implement this.
Can i get some help please?
Pins in Google Maps are called Markers and they are pretty simple to create.
Following what is documented from the Google Maps API here, you just use the addMarker() method to create a marker and can customize the options of where it should be placed and the title to show when it is clicked on
#Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
}
Mapbox TileOverlays require attribution. How can I set this in java?
Here is my code to change the tileOverlay to a custom one. The attribution I have to use is this link: http://www.openstreetmap.org/copyright
overlayString = "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png";
provider = new CustomUrlTileProvider(256, 256, overlayString);
mSelectedTileOverlay = gMap.addTileOverlay(new TileOverlayOptions().tileProvider(provider).zIndex(-1));
I'd suggest using a Textview the sits on top on the mapview and has a clickable url to the copyright link
I have implemented the Google Places API. If I search for "Cafes near my location" in Google Maps I get a list of results, whereas, when I perform the same search with Google Places I get 0 results.
I also used a Place.TYPE_CAFE PlaceFilter (i.e. a filter for cafes) in my implementation of Google Places and it returns 0 results for cafes even though there are at least 2 cafes within 0.5 miles of my location according to Google Maps when I search for "Cafes near my location"
Here is my implementation of the PlaceFilter with the Places.PlaceDetectionApi
ArrayList<Integer> placeType = new ArrayList<Integer>();
placeType.add(Integer.parseInt(""+Place.TYPE_CAFE));
PlaceFilter placeFilter = new PlaceFilter(placeType,false,null,null) ;
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, placeFilter);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
#Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i("placesAPI", String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
})
Problem in a nutshell: How do I make the Google Places' search functionality return as many places as Google Maps' ?
If you need any more code let me know,
Thanks in advance
The Google Places API may have improved since I asked this question but one solution to this problem is to use the Google Maps Web API.
You may use Place Autocomplete service in the Google Places API for Android and you can also get palces near by your location using Google Place API. Autocomplete returns place predictions in response to user search queries. As the user types, the autocomplete service returns suggestions for places to points of interest.
Here's a sample tutorial showing nearby places using Google Places API and Google Maps Android V2: http://wptrafficanalyzer.in/blog/showing-nearby-places-using-google-places-api-and-google-map-android-api-v2/
I am working on a vehicle routing algorithm I need to show vehicles on maps with there driver name on top of the label. I have done the marker part it looks like this.
However I would like to display driver's name on top of every marker. Can you suggest me any way to do it?
My google maps static api url looks like this
https://maps.googleapis.com/maps/api/staticmap?center=26.900,75.800&zoom=11&size=400x400&markers=color:blue|label:Driver|&markers=color:green|label:Req|26.925571778374632,75.81166033197894|&markers=color:blue|label:others|26.944421737574313,75.8072312248272|26.941722318252367,75.82851178160593|26.909618922760885,75.85079885210592|26.92537722447672,75.85626510000787|26.969253598622025,75.81687986464266|26.933707124740607,75.84999920863306|26.986333832648626,75.88755301718626|26.945330532812793,75.81567681826434|26.942938812152843,75.81989078933901|&markers=color:red|label:Req|26.8983489,75.796436|
Ps: I am using java.
I think the best you can do with the Static Maps API v2 is to have different initials and colors for different markers. Like this example.
You may be able to do something with the custom icons too, but it does not seem to be working as far as I can tell.
The best practice here is to implement it using the JavaScript API v3 instead.
Is this possible with the version you're using?
#Override
public void onMapReady(GoogleMap map) {
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
Here is the code in action: https://developers.google.com/maps/documentation/android/
This is my first post here, so I hope I'll explain my problem clear enough:
I'm extending the FragmentActivity class to create a HeatMapActivity. In this activity I use a GoogleMap object, which I obtain as follows:
// Try to obtain the map from the SupportMapFragment.
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.heatmap)).getMap();
Now, after doing a null-Check etc., I'm adding a TileOverlay in the setUpMap() method, as shown below:
// Configure and add overlay
tileProvider = new HeatMapTileProvider(map);
map.addTileOverlay(new TileOverlayOptions()
.tileProvider(tileProvider));
Ok, so far no problem at all. I implemented the TileProvider interface to provide the tiles for the HeatMap overlay.
I want to use the Projection object for converting latitude/longuitude to and from pixels on the screen. The Projection object should be returned by the getProjection() method of the GoogleMap class.
So now here's the problem: If I use the following code in the HeatMapActivity class, everything is fine:
System.err.println("Test1: " + map.getProjection().fromScreenLocation(new Point(50, 50)));
But if I forward the GoogleMap object to the TileProvider, respectively to the renderer I use, the code is not working anymore:
public byte[] render(int x, int y, int zoom, GoogleMap map) {
...
System.err.println("Test2: " + map);
System.err.println("Test3: " + map.getProjection().fromScreenLocation(new Point(50, 50)));
...
}
I definitely know, that the map parameter is not null (see Test 2), but the code just seems to block when I call getProjection(). There is no error coming up and if I don't use the Projection object, everything else is working fine. I don't have any clue, why I should not be allowed to call getProjection() from another class than the activity...
I am using the ADT bundle for Windows (version x86_64-20130729), Android SDK version from 8 to 17, testing on Android 2.3.5 at the moment. The map is displayed, the needed libraries are included and the permissions are set in the android manifest.
Any ideas? Any help or hints are appreciated.
Seb
The issue here is that getTile (and your render method) are called outside UI thread.
This will cause exception, which you won't see, because it is probably silently handled by the code calling getTile. This is really bad it doesn't crash, so someone could post an issue on gmaps api issues.
Try to wrap call to getProjection in try-catch to see it.
Because you should not interact with GoogleMap outside of main thread, you will have to find another way to achieve, what you want to achieve...
Anyway, I can imagine no good reason for a need to call getProjection in getTile. Maybe another question describing your real problem?