iOS Google Sdk Map Cannot Create Dotted Polylines

ios Google SDK Map cannot create dotted polylines

Yes it does, for dashed line you need to configure few things.

First define few variables

NSArray *_styles;
NSArray *_lengths;
NSArray *_polys;
double _pos, _step;

The define in the function, outside the for..loop not inside as you are doing

- (void) createDashedLine:(CLLocationCoordinate2D )thisPoint:(CLLocationCoordinate2D )nextPoint:
(UIColor *)colour
{

double difLat = nextPoint.latitude - thisPoint.latitude;
double difLng = nextPoint.longitude - thisPoint.longitude;
double scale = camera.zoom * 2;
double divLat = difLat / scale;
double divLng = difLng / scale;
CLLocationCoordinate2D tmpOrig= thisPoint;

GMSMutablePath *singleLinePath = [GMSMutablePath path];

for(int i = 0 ; i < scale ; i ++){
CLLocationCoordinate2D tmpOri = tmpOrig;
if(i > 0){
tmpOri = CLLocationCoordinate2DMake(tmpOrig.latitude + (divLat * 0.25f),
tmpOrig.longitude + (divLng * 0.25f));
}
[singleLinePath addCoordinate:tmpOri];
[singleLinePath addCoordinate:
CLLocationCoordinate2DMake(tmpOrig.latitude + (divLat * 1.0f),
tmpOrig.longitude + (divLng * 1.0f))];

tmpOri = CLLocationCoordinate2DMake(tmpOrig.latitude + (divLat * 1.0f),
tmpOrig.longitude + (divLng * 1.0f));

}

GMSPolyline *polyline ;
polyline = [GMSPolyline polylineWithPath:singleLinePath];
polyline.geodesic = NO;
polyline.strokeWidth = 5.f;
polyline.strokeColor = colour;
polyline.map = mapView_;

//Setup line style and draw
_lengths = @[@([singleLinePath lengthOfKind:kGMSLengthGeodesic] / 100)];
_polys = @[polyline];
[self setupStyleWithColour:colour];
[self tick];
}

- (void)tick {
//Create steps for polyline(dotted polylines)
for (GMSPolyline *poly in _polys) {
poly.spans =
GMSStyleSpans(poly.path, _styles, _lengths, kGMSLengthGeodesic, _pos);
}
_pos -= _step;
}

-(void)setupStyleWithColour:(UIColor *)color{

GMSStrokeStyle *gradColor = [GMSStrokeStyle gradientFromColor:color toColor:color];

_styles = @[
gradColor,
[GMSStrokeStyle solidColor:[UIColor colorWithWhite:0 alpha:0]],
];
_step = 50000;
}

Hope it helps.
Cheers.

IOS cannot add poly markers only polylines drawn no markers added

you never use the path point's coordinate but a hardcoded one:

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);

use the path

CLLocationCoordinate2D position = [path coordinateAtIndex:i];

Google Map SDK: Draw correct polyline in google map as Device Moves in Background

add a NSLocationAlwaysUsageDescription and a UIBackgroundModes -> "location" to Info.plist

AND

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
manager.allowsBackgroundLocationUpdates = YES;
}

Before allowing background location updtaes:
enter image description here

After Allowing background location updtaes:
enter image description here

Most of this itinerary has been drawn in the background.

PolyLines not showing in google maps

you are setting wrong bounds so it is not showing on your map . I have tried your code it is working fine . Please change your bounds area as (0,0,0,0)

 func getPolylineRoute(from source: CLLocationCoordinate2D, to destination: CLLocationCoordinate2D){

let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)

let url = URL(string: "https://maps.googleapis.com/maps/api/directions/json?origin=\(source.latitude),\(source.longitude)&destination=\(destination.latitude),\(destination.longitude)&sensor=true&mode=driving&key=AIzaSyAyU5txJ86b25-_l0DW-IldSKGGYqQJn3M")!

let task = session.dataTask(with: url, completionHandler: {
(data, response, error) in

DispatchQueue.main.async {

if error != nil {
print(error!.localizedDescription)
AppManager.dissmissHud()
}
else {
do {
if let json : [String:Any] = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]{

guard let routes = json["routes"] as? NSArray else {
DispatchQueue.main.async {
AppManager.dissmissHud()
}
return
}

if (routes.count > 0) {
let overview_polyline = routes[0] as? NSDictionary
let dictPolyline = overview_polyline?["overview_polyline"] as? NSDictionary

let points = dictPolyline?.object(forKey: "points") as? String

self.showPath(polyStr: points!)

DispatchQueue.main.async {
AppManager.dissmissHud()

let bounds = GMSCoordinateBounds(coordinate: source, coordinate: destination)
//below bounds change as 0 check it on full screen
let update = GMSCameraUpdate.fit(bounds, with: UIEdgeInsetsMake(0, 0, 0, 0))
self.vwMap!.moveCamera(update)
}
}
else {
DispatchQueue.main.async {
AppManager.dissmissHud()
}
}
}
}
catch {
print("error in JSONSerialization")
DispatchQueue.main.async {
AppManager.dissmissHud()
}
}
}
}
})
task.resume()
}

Android Google maps SDK draw a polyline with a dashed line

I'm afraid this answer wont suit you:

Currently there is no easy way of doing this on Google Maps v2. If you want to use the tools provided by Google you must split your Polyline in to several small ones, this SO question has a example: How to draw dashed polyline with android google map sdk v2?

If you really want dashed lines and need to draw many (really many) I would suggest creating a overlay and draw on that instead and move it with the map. However it isn't an easy approach considering e.g scaling and rotating of the map. But for small - medium amount of dashed lines it is not worth the pain.

There will likely be a dashed feature in Google Maps V3 considering that Google Maps JS v3 has it.



Related Topics



Leave a reply



Submit