Move google map but not the marker like Uber [closed] - ios

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 5 years ago.
Improve this question
I am developing an app where I am using Google maps.
I want to have a marker pin to be steady in the centre of screen and if I move the map the pin should not be moved.
When I leave the map, I want the address from the map where the steady marker id kept.
Any help will be appreciated

You can use this things
mapView.delegate = self;
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
let coordinate = mapView.projection.coordinate(for: markerView.center)
print("latitude " + "\(coordinate.latitude)" + " longitude " + "\(coordinate.longitude)")
}
Now you need to add just a imageview on top of your mapview in the center and it will work same as uber.
Remember the height of pin icon should be doubled.
You can use this icon if you need

You could add a image layer above the map view, containing the image of the pin pointing to the center of the screen. When the user leaves the map pick the location from the center of the screen.

Fix your marker view on the center in your view.
Add GMSMapview in your top view.
Set Delegate to your map view.
GMap.delegate = self; // Add delegate - GMSMapViewDelegate to your viewcontroller
To detect if the user dragged the map:
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
let coo = GMap.projection.coordinate(for: markerView.center)
selectedLocation = CLLocation(latitude: coo.latitude, longitude: coo.longitude)
getAddress() //get address of your selected location
}

Related

Check if MKPolygon is inside visible rect or another MKPolygon

I have a MKMapview with lot of polygons added as overlays, To optimize the memory I need to know before adding an overlay if the polygon is inside visible area of the MKMapview
I can even create a whole visible area polygon with mapview all corner coordinates, for example topLeft as below
func topLeftCoordinate() -> CLLocationCoordinate2D {
return convert(bounds.origin, toCoordinateFrom: self)
}
with all the corner coordinates, I can create a current_visible_area_polygon and I want to check the polygons I add is inside this current_visible_area_polygon.
so it comes down to two questions
Is it possible to check if a polygon is inside another polygon or atleast intersects OR
if a polygon is inside visible maprect
I found the answer to be the following
let mapView: MKMapView
let mkPolygon: MKPolygon
mapView.visibleMapRect.isIntersects(mkPolygon)

Moving google maps marker

I'm using Swift 3 and I want to create a moving marker in my map view, so that if the user touches the screen and moved the marker also moves with the page.
How can I fix this?
Use GMSMapViewDelegate method :
mapView:didChangeCameraPosition:
Set GMSMarker in this method at camera position.
This method call when camera position change in map.
func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
// Apply set marker logic here
}

How to put iOS Magnifying Glass effect on Google Maps (GMSMapKit)

How to put the UITextView texting editing Magnifying Glass on the Google Maps GMSMapView
For example I have a GMSMapView to show my current location
I want to trigger a overlay Magnifying Glass view when calling delegate methods
mapView:didChangeCameraPosition: and mapView:willMove: in GMSMapViewDelegate
The purpose is to provide an overlay zooming subView according to the user tapping coordinates (like github.com/acoomans/iOS-MagnifyingGlass did on ImageView)
Please let me know if this is possible for Google Maps for iOS or if iOS MapKit can support this kind of customization
Update #2: mapView.addSubView(mapSubView) works now. But it pollutes the Main GMSMapView
Update #1: I tried mapView.addSubView, it seems does not work for GMSMapView although inherited from UIView
The intention of below code snippet is to retrieve user's touch point at the map and converts it into CGPoint for creating a second GMSMapView
func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
println("Tapping at (\(coordinate.latitude), \(coordinate.longitude))")
// 1. retrieve the user touch position as CLLocationCoordinate2D
let cameraPosition = GMSCameraPosition.cameraWithLatitude(coordinate.latitude, longitude: coordinate.longitude, zoom: 20)
// 2. convert it into CGPoint
let screenTouchPoints = mapView.projection.pointForCoordinate(coordinate)
// 3. set the CGRect for init the mapSubView
let frame = CGRectMake(screenTouchPoints.x, screenTouchPoints.y, 100, 100)
mapSubView = GMSMapView.mapWithFrame(frame, camera: cameraPosition)
// 4. Finally add to the main Map View
mapView.addSubview(mapSubView)
}
It seems plausible with a GMSMapView. Maybe have a second GMSMapView on top of the original(high corner radius to create a circle?) and animate the alpha and scale along with the zoom level within the second map. Do this whenever mapView:didChangeCameraPosition etc is called.
By taking reference to this Github Project, GMSMapView can also be magnified by putting the view hierarchy in this way:
View Controller > Magnifying View > The View want to be zoomed
The core rendering mechanism is
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, self.frame.size.width/2, self.frame.size.height/2 );
CGContextScaleCTM(context, scale, scale);
CGContextTranslateCTM(context, -touchPoint.x, -touchPoint.y + (self.scaleAtTouchPoint? 0 : self.bounds.size.height/2));
[self.viewToMagnify.layer renderInContext:context];
}
loupe = ACLoupe()
magnifyingGlass = ACMagnifyingGlass()
magnifyingView = ACMagnifyingView(frame: self.view.frame)
magnifyingView.magnifyingGlass = loupe
magnifyingView.addSubview(Your_Subview_here)
by this method the magnifying view can capture current frame context, because Magnifying View is the container of other views so that the capturing can show the current UI situation and zoom by 1.5 times (default scale factor)

How to Get MapView Center Latitude and Longitude Every time when Mapview are Swiped in ios?

I'm using the Google Map SDk for showing location to a user in my app. In my app I want to center the latitude and longitude to the user every time they swipe/zoom or change the map.
For that I put one center location in my GMSMapView using the following code:
- (void) mapView: (GMSMapView *)mapView
didChangeCameraPosition: (GMSCameraPosition *)position
{
double latitude = mapView.camera.target.latitude;
double longitude = mapView.camera.target.longitude;
// now do something with latitude and longitude
}
But this is not giving me the center location and latitude every time. How can I fix this?
The documentation on didChangeCameraPosition here:
https://developers.google.com/maps/documentation/ios/reference/protocol_g_m_s_map_view_delegate-p#aabd01d59d7680799a0c24d3c8b5e4622
Says this:
This may not be called for all intermediate camera positions. It is always called for the final position of an animation or gesture.
Set google map delegate first
mapview.deligate=self;
this will give you centre coordinate

MKMapView centerLocation

In my application there is an MKMapView and I am trying to get the center coordinates of the map region that is currently visible. I am using following method so that if user moves the visible region I'll get new center coordinates.
- (void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated
{
CLLocationCoordinate2D centre = [mapView centerCoordinate];
NSLog(#"MAP CENTER = %f,%f",centre.latitude,centre.longitude);
}
the problem is that when I switch to the UIViewController that contains MKMapView it gives MAP CENTER = 0.000000,0.000000 for two times then gives the actual coordinates MAP CENTER = 55.755786,37.617633. I want the actual coordinates as soon as I switch to that UIViewController.
Is the coordinates (55.755786,37.617633) your current location ?
MKMapView takes some time to get a lock on GPS to fetch the coordinates for your current location. Until then centerCoordinate might return (0,0)
Try this this may help you.
self.mapView.centerCoordinate = self.mapView.userLocation.location.coordinate;

Resources