I am working on a project which allows a User to place and name a point on a map. The problem is that after the point has been placed, if the user zooms out, the point moves with the map. I have a couple of screenshots to illustrate the problem.
1: After point has been placed
2: Zoomed out
Any help is appreciated !
You haven't set the appropriate anchor for your custom icon (probably should be the point of the pin).
Seems just to be that icon, tried another and it works fine.
Related
I have been trying to achieve this for a long time. But not being able to. So I did really need some help here with this.
Current method - refer the below image
like you see above, , marker image is an ImageView and is properly placed so that the tip of the marker is pointing to the center of the screen. And fetch a latlon I will be reading maps idle or move state and will use the below methods to get the latlons.
googleMap.getCameraPositionLatitude();
googleMap.getCameraPositionLongitude();
But, the real problem is with the below format which I want to achieve. because this would improve UI/UX as the view is placed in a place where user can view the location clearly to which he is pointing to clearly(of-course the bottom part of the screen would be filled up with suggestions or any further changes that I think of).
Please refer the below image -
Here I am stuck. i dont find any methods that provide me latlon from that portion of the screen. I really need help from you guys to solve this. i want to pull the location from where the tip of the view is pointing w.r.t the second image (above image). if I use googleMap.getCameraPositionLatitude();
googleMap.getCameraPositionLongitude(); Which is in appropriate as it will get me latlons from center of the screen.
kindly help me out with this !
Thanks in advance :)
You can use Map Padding for that. With .setPadding() method you can move map center to position what you need. Also take a look at this question of David.
I am using Google map v2,everything works fine from viewing the map to applying polyline between markers.However there is one thing that I need to accomplish, it is to put arrow header inside the commonly used map marker.
The arrow must rotate or point to the direction of the next location and so on. here's the image looks like
map_marker
I have tried using only the arrow alone and it works fine with the use of .rotation(bearing) but my boss wants it inside the commonly used marker and only the arrow will move.They have a working sample but it works only in the browser using javascript.I haven't found samples or at least documentation about it on the internet only this similar question
How to display direction arrows in the map marker for google maps v2 android but unfortunately no one answered. I have also tried
.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(R.drawable.arrow_header)))
but the both the marker and arrow moves
I have done everything to accomplish this task and this would be my last resort just to inform my boss that just in case there is no way that it'll work on android. Thank you..
I have a pin which has a arrowed-tip. When placed a marker, the tip is not actually pointing accurately to the tap location. It seems my pins are being positioned base on their center. I want to move this center by a particular offset.
Here is what I am currently using (among many other custom pins I have). These are sized at 250x250:
This is a circular button. Notice it has a arrow on the bottom-most part (pointing downwards).
Now, lets place this pin on mapbox:
#Override
public void onMapClicked(#NonNull LatLng point)
{
mPopularView.showPinSelectedPopup(false);
if(!mIsOnMyRecommendationMode)
return;
IconFactory iconFactory = IconFactory.getInstance(getContext());
Drawable iconDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_map_bank_blue_pin);
Icon icon = iconFactory.fromDrawable(iconDrawable);
MarkerOptions markerOption = new MarkerOptions();
markerOption.setPosition(point);
markerOption.title("Just a I don't know where I am!");
markerOption.setSnippet("Hello World! I don't know where I am!");
markerOption.setIcon(icon);
mPopularView.getMapboxMap().addMarker(markerOption);
mIsOnMyRecommendationMode = false;
}
Fairly simple, just like in the docs. It works very well. Look at the following pic:
I hope this pic will paint a thousand words. Please do not suggest of adjusting the LatLang to account for the offset. That will be incorrect on my use case. It has to be the pixel position of the icon itself. MapBox should have accounted for this when they allowed devs to develop their own custom pins (WE ARE GOING TO PUT ARROWS ON OUR PINS!).
Currently, I set the height of the custom pin icon with double the height. But one caveat I found is that I can actually select the bottom half of the now longer pin icon. For example:
Notice the image above. The height of that image has been doubled. When I placed this, now the arrow correctly points to the area I tapped. One caveat is that, when you pressed below the pin, it still detects click callback. Guess why... because the bounds (specifically the height) of the custom icon is longer and so does its click boundaries. Thus, I cannot put pins below it as it detects it as onMarkerClicked().
How can I get around this? Any ideas?
Thanks!
Not So Elegant Solution
Just wanted to post this as answer in case somebody else is experiencing the same. My situation is kind of extreme and I really need to load the bitmap on the pin instead of some other method proposed by cammace. I use the old fashioned pixel-positioning to get exactly what I wanted. Fortunately, MapBox is equipped with transforming screen coordinates to map coordinates and vice-versa.
I tested this on both tablet and a mobile phone and it doesn't seem to get affected by the screen size. Its pointy edge now actually points at my designated target:
LatLng position = new LatLng();
position.setLatitude(lat);
position.setLongitude(long);
PointF pointF = mMapboxMap.getProjection().toScreenLocation(position);
pointF.offset(0f, -(icon.getBitmap().getHeight() / 2.0f));
position = mMapboxMap.getProjection().fromScreenLocation(pointF);
This is not the most elegant solution. I hope this helps anyone who are in similar situation like me. Nudging the pin upward is only representational, I still read the original latlong values of pins from our homebrew server as is, I just placed the latlong values a little bit off upwards during marker placement.
Zooming also doesn't seem to be affected by this, I tried both not placing it by pixels and one with using this solution.
As I have said, if this is totally wrong. Let me know.
If there are some caveats on this approach. Please do let me know.
With the release of 4.2.0 last week, we have three ways of adding markers. The current way you are adding them will indeed mean that you will need to add padding to your image so that the image is centered (this is what we are doing with the default marker).
The second option you have is using MarkerViews. Simply replace this line:
MarkerOptions markerOption = new MarkerOptions();
to this:
MarkerViewOptions markerOption = new MarkerViewOptions();
this will expose a few more options including an anchoring option. Marker views have one issue which is performance, so if you are adding an abundance of markers or don't like them being slightly out of sync with the map, you have a third option.
The third option will be using Runtime Styling to create a symbol layer and making use of the offset property found in the style spec. Have a look at this example found in our demo app for better understanding of the potential of using runtime styling.
Android: I am using a mapview and ItemizedOverlay. I am ploting a drawable on that, it does not shows correct place. It shows correct position on map when full zoom in but when it is zoom out the marker is moving from correct position.
Can any one know the solution. Should I need to do something in draw of ItemizedOverlay.?
Does anyone knows the solution. Please help me.
regards,
dharma
I am having an app which tracks the Geopoints of the user. I simply fetch these points and use them to draw the path on Map View.
My issue is, when I see the path tracked by user, the path seems to be correctly plotted but, when I have a first look over the map,it does not show me an entire zoomed out view of the map where I can see all the track path. Instead the map begins with from where I started tracking and then I need to scroll all my way to see the further tracks.
Please Help. :)
Thanks In Advance.
Use MapController.zoomToSpan(...), you can get the span from your ItemizedOverlay methods getLatSpan(int) and getLonSpan(int). zoomToSpan(...) is a best effort method and does not guarantee that all points will be visible.