Reputation: 73
Multiple marker doesn't show on google map using swift 4.1 i am connect JSON and result show on console but how can I connect with latitude and longitude with Google maps.
let jsonUrl = URL(string: "http://assetlinkasia.no-ip.biz:8001/hf_tracker/api/userdevices.php?accesskey=12345&user_id=1")
if let url = jsonUrl {
let data = NSData(contentsOf: url)
if let data = data {
do{
let jsonObject = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments)
if let object = jsonObject as? [NSString: AnyObject]{
if let allDevices = object["data"] as? [[NSString: AnyObject]]{
print("Successfull")
print(allDevices)
}
}
}catch{
print("Error Eccurred")
}
}
}
and this is my google map code here:
let getLongijson = Double("67.0011")
let getlatijson = Double("24.8607")
let camera = GMSCameraPosition.camera(withLatitude: getlatijson!, longitude: getLongijson!, zoom: 13.0)
let mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
self.view = mapView
// meanView.addSubview(mapView)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: getlatijson!, longitude: getLongijson!)
marker.infoWindowAnchor = CGPoint(x:0.10, y:0.10)
marker.title = HeadingName
marker.snippet = Countory
marker.icon = UIImage(named: "markers")
marker.map = mapView
//User Location
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
// self.menuFunction()
mapView.delegate = self
Upvotes: 1
Views: 688
Reputation: 120
Try this one
Objective-c
count = (int)locatorObject.LocationList.count;
for(int i=0;i< count;i++)
{
LocationDetails *locator = locatorObject.LocationList[i];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([locator.Lat floatValue],[locator.Long floatValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = locator.Address;
marker.map = _googleMapView;
}
swift
for i in 0..<count {
var locator: LocationDetails? = locatorObject.locationList[i]
var position: CLLocationCoordinate2D = CLLocationCoordinate2DMake(locator?.lat, locator?.long)
var marker = GMSMarker(position: position)
marker.title = locator?.address
marker.map = googleMapView
}
Upvotes: 2