How to add drop pin in Google Map iOS - google-maps

How can I add "drop pin" and the dropping on above animation in Google Map iOS?
I can only find marker in SDK, and the appearAnimation property only provides pop up animation.

Use MKAnnotationView from MapKit. From the documentation on Using the Standard Annotation Views:
MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:#"MyCustomAnnotation"] autorelease];

In the GMSMarker Class reference it says for the appearAnimation property:
Controls the animation used when this marker is placed on a GMSMapView (default kGMSMarkerAnimationNone, no animation).
Using the Google Maps SDK for iOS a marker can be made like this:
GMSMarker *startMarker = [GMSMarker markerWithPosition:#"NYC"];
startMarker.appearAnimation = kGMSMarkerAnimationPop;
startMarker.title = #"Start";
startMarker.snippet = #"My address";
startMarker.map = mapView;

If you set the title or snippet property of a Marker then the tooltip will show when tapped.
marker.title = #"Hello World";
and/or
marker.snippet = #"Hello Snippet";

For swift:
locationMarker.appearAnimation = kGMSMarkerAnimationPop
locationMarker.icon = UIImage(named: "testImage") as UIImage?

Related

Vaadin how to add Google heat map

I have a Vaadin application where I would like to integrate Google heatmaps. I am using com.vaadin.tapio.googlemaps dependency for displaying a map and it works fine. However, I am not sure how to add a heatmap layer on top of the Google map and I couldn't find any relevant resource.
Relevant part of my trial code looks like this:
VerticalLayout rootLayout = new VerticalLayout();
rootLayout.setSizeFull();
// Google Map
GoogleMap googleMap = new GoogleMap("api_key", null, null);
googleMap.setZoom(10);
googleMap.setSizeFull();
googleMap.setMinZoom(4);
googleMap.setMaxZoom(16);
Panel mapsPanel = new Panel();
mapsPanel.setSizeFull();
mapsPanel.setContent(googleMap);
rootLayout.addComponent(mapsPanel);
double centerLon = 8.5417;
double centerLat = 47.3769;
googleMap.setCenter(new LatLon(centerLat, centerLon));
GoogleMapMarker centerMarker = new GoogleMapMarker("Zurich", new LatLon(centerLat, centerLon),true, null);
googleMap.addMarker(centerMarker);
HeatMapLayer heatMapLayer = HeatMapLayer.newInstance(HeatMapLayerOptions.newInstance());
// Add data to heatmap
...
// How can I add this HeatMapLayer to the existing map?
// Or do I need a different approach?
UI.getCurrent().setContent(rootLayout);
HeatMapLayer is a GWT (client-side) object, you can't use it directly with GoogleMap which is a server-side component. You can check this fork of com.vaadin.tapio.googlemaps, it adds support for HeatMapLayer with GoogleMapHeatMapLayer class.

about positioning myself,some problems

I am a new to google map sdk for ios.I have added a map on a view.When I enter this mapView,I want to positioning myself.So I wrote :
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
_iMapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 480) camera:camera];
self.iMapView.myLocationEnabled = YES;
self.iMapView.delegate=self;
GMSMarkerOptions *annotation = [[GMSMarkerOptions alloc] init];
annotation.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
annotation.title = #"Sydney";
annotation.snippet = #"Australia";
//annotation.infoWindowAnchor=CGPointMake(0.5, 0.5);
[self.iMapView addMarkerWithOptions:annotation];
//[self.view addSubview:self.iMapView];
self.view=self.iMapView;
but I find the mapView view in the coordinate(33.8683,151.2086),I just want to move the mapView to the wyposition. I also find google have no callback function reference to
self.iMapView.myLocationEnabled = YES;
thank you for you reply.
To animate/set the camera to your current position you first have to:
self.googleMapsView.myLocationEnabled = YES;
Then in the documentation of the GMSMapView header file you will find the following comment:
/**
* If My Location is enabled, reveals where the user location dot is being
* drawn. If it is disabled, or it is enabled but no location data is available,
* this will be nil. This property is observable using KVO.
*/
#property (nonatomic, strong, readonly) CLLocation *myLocation;
So you can setup a key value observer in your viewWillAppear Method and then you get your location update with the Location Manager of the GoogleMaps SDK.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Implement here to check if already KVO is implemented.
...
[self.googleMapsView addObserver:self forKeyPath:#"myLocation" options:NSKeyValueObservingNew context: nil]
}
And then observe the property.
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:#"myLocation"] && [object isKindOfClass:[GMSMapView class]])
{
[self.googleMapsView animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:self.googleMapsView.myLocation.coordinate.latitude
longitude:self.googleMapsView.myLocation.coordinate.longitude
zoom:self.googleMapsView.projection.zoom]];
}
}
Do not forget to deregister your observer in the viewWillDisappear.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Implement here if the view has registered KVO
...
[self.googleMapsView removeObserver:self forKeyPath:#"myLocation"];
}
Best regards
NOTE: This answer is wrong, see Robert's answer.
The Google Maps SDK for iOS doesn't have any delegate to let you know when the device's position has changed.
You would need to use the CLLocationManager class yourself, to get the device's current position, and then update the map view.
UPDATE:
To update the map view from the new CLLocation provided by the location manager, you do something like this:
GMSMapView* mapView = ...;
CLLocation* location = ...;
GMSCameraPosition* camera = [GMSCameraPosition
cameraWithLatitude: location.coordinate.latitude
longitude: location.coordinate.longitude
zoom: 6];
mapView.camera = camera;
Or if you want the map view to animate to the new location, then use this:
[mapView animationToCameraPosition: camera];

How to get CGPoint of location with google maps sdk for iOS?

How to get CGPoint of location with google maps sdk for iOS ?
I need add pinview on user location.
It's basically the opposite of this question, for example:
GMSMapView* mapView = ...;
CLLocationCoordinate2D coordinate = ...;
...
CGPoint point = [mapView.projection pointForCoordinate: coordinate];
Ok, according to your question do you want to convert the userlocation into the cgpoint, is that..
try use this.
CGPoint newCenter = [self.map convertCoordinate:coord toPointToView:self.map];
Regards.

disable all other views not including map view Gmap2

I am using Google Map v2 and I only want map view and nothing more. I also would like to get rid of the zoom in and out buttons.
If anyone knows what I need to add to the following that would be great.
function stores()
{
$('#storelist ul#stores').html("");
fetch(203,"task=location&location=vic");
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(-37.810013, 144.962683), 8);
map.setUIToDefault();
yellowIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/orange/blank.png";
markerOptions = { icon:yellowIcon };
}
Remove map.setUIToDefault(). It adds the default look and feel to the Map.
(Reference docs: http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GMap2.setUIToDefault)
If you want, you can also customise how the map can be interacted with. For example map.disableDoubleClickZoom() or map.disableDragging(). See the reference above for details.

How to add logo to copyrights in google maps?

I'm adding new layers to my google map application and want to add new logo there. Like in this case:
Is there some clean way how to do it in the google maps API, like using GCopyright and GCopyrightCollection classes in google maps API v2? Or is this missing in v3 (like many other features) and I have to do it manually?
In Google Maps API v3, there's no copyright API. Note that in v2, the GCopyright was used to add textual copyright information, not a logo.
To add a logo to the map you have to create a custom control.
Create a logo custom control:
function MyLogoControl(controlDiv) {
controlDiv.style.padding = '5px';
var logo = document.createElement('IMG');
logo.src = 'img/my_logo.png';
logo.style.cursor = 'pointer';
controlDiv.appendChild(logo);
google.maps.event.addDomListener(logo, 'click', function() {
window.location = 'http://www.example.com';
});
}
Add the control to the map:
var logoControlDiv = document.createElement('DIV');
var logoControl = new MyLogoControl(logoControlDiv);
logoControlDiv.index = 0; // used for ordering
map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(logoControlDiv);
Similarly a copyright information can be added. But you can't modify the default copyrights, you have to add yours somewhere next to the defaults.
If you want to add a copyright information that's bound to a bounding box and/or zoom level, you have to create such behaviour manually.