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 8 years ago.
Improve this question
I want Step by Step navigation by using GPS with google Maps and how to achieve that one.
Any help really appreciated
Thank you
you need a google API Services and they provide full Route path when you give Startpoint and Destination point and call the api with the following
http://maps.google.com/maps/api/directions/json?sensor=true&origin=23.027439,72.523089&destination=23.029108,72.507570
here my startingpoint is origin=23.027439,72.523089 and destintaion is destination=23.029108,72.507570
so now google will provide following data
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 23.0296906,
"lng" : 72.5234184
},
"southwest" : {
"lat" : 23.026354,
"lng" : 72.50715599999999
}
},
"copyrights" : "Map data ©2014 Google",
"legs" : [
{
"distance" : {
"text" : "2.2 km",
"value" : 2249
},
"duration" : {
"text" : "5 mins",
"value" : 325
},
"end_address" : "Sarkhej - Gandhinagar Highway, Satellite, Ahmedabad, Gujarat 380054, India",
"end_location" : {
"lat" : 23.0290924,
"lng" : 72.5076297
},
"start_address" : "38, Indus Park, Satellite, Ahmedabad, Gujarat 380015, India",
"start_location" : {
"lat" : 23.027439,
"lng" : 72.5230894
},
"steps" : [
{
"distance" : {
"text" : "68 m",
"value" : 68
},
"duration" : {
"text" : "1 min",
"value" : 24
},
"end_location" : {
"lat" : 23.0269233,
"lng" : 72.5227287
},
"html_instructions" : "Head \u003cb\u003esouthwest\u003c/b\u003e toward \u003cb\u003eSatellite Rd\u003c/b\u003e",
"polyline" : {
"points" : "oppkCitsyLXPJFh#\\VN"
},
"start_location" : {
"lat" : 23.027439,
"lng" : 72.5230894
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "85 m",
"value" : 85
},
"duration" : {
"text" : "1 min",
"value" : 30
},
"end_location" : {
"lat" : 23.0265039,
"lng" : 72.5234184
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eSatellite Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Hanuman Mandir (on the left)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "gmpkCarsyLVa#`#u#Pc#FM"
},
"start_location" : {
"lat" : 23.0269233,
"lng" : 72.5227287
},
"travel_mode" : "DRIVING"
},
you have to understand the documentation for using google direction services for that here is the link https://developers.google.com/maps/documentation/javascript/directions.
here is a simple logic you can use after that.
what you have to do is to store this steps dictionaryArray in array and then try to fetch it one by one.
Check didUpdateToLocation method for current Lat Long and if your current location is near by the vlaue of step Dcitionay's endLocation point and if its near by then you can alert the message of html_instructions Value that which direction user has to go next and increase your index for steps array dictionary and same do it for the last index of steps.
if need any help feel free to ask.
Related
So the JSON variable let json = JSON(nearbyChargingSites.jsonString!) contains the current data.:
{
"timestamp" : 1626902257093,
"superchargers" : [
{
"location" : {
"lat" : 63.325319,
"long" : 10.305137
},
"total_stalls" : 19,
"distance_miles" : 10.064082000000001,
"type" : "supercharger",
"site_closed" : false,
"available_stalls" : 15,
"name" : "Leinstrand, Norway - Klett"
},
{
"location" : {
"lat" : 63.466445999999998,
"long" : 10.91766
},
"total_stalls" : 16,
"distance_miles" : 11.838984999999999,
"type" : "supercharger",
"site_closed" : false,
"available_stalls" : 16,
"name" : "Stjørdal, Norway"
},
{
"location" : {
"lat" : 63.734355000000001,
"long" : 11.281487
},
"total_stalls" : 12,
"distance_miles" : 31.206503999999999,
"type" : "supercharger",
"site_closed" : false,
"available_stalls" : 11,
"name" : "Levanger, Norway"
},
{
"location" : {
"lat" : 62.832030000000003,
"long" : 10.009639999999999
},
"total_stalls" : 20,
"distance_miles" : 44.117753,
"type" : "supercharger",
"site_closed" : false,
"available_stalls" : 17,
"name" : "Berkåk, Norway"
}
],
"congestion_sync_time_utc_secs" : 1626902199,
"destination_charging" : [
{
"distance_miles" : 23.366278999999999,
"name" : "Bårdshaug Herregård",
"location" : {
"lat" : 63.299208,
"long" : 9.8448650000000004
},
"type" : "destination"
},
{
"distance_miles" : 38.390034,
"name" : "Fosen Fjordhotel",
"location" : {
"lat" : 63.959356999999997,
"long" : 10.223908
},
"type" : "destination"
},
{
"distance_miles" : 46.220022999999998,
"name" : "Falksenteret",
"location" : {
"lat" : 63.293301999999997,
"long" : 9.0834460000000004
},
"type" : "destination"
},
{
"distance_miles" : 54.981445000000001,
"name" : "Væktarstua",
"location" : {
"lat" : 62.908683000000003,
"long" : 11.893306000000001
},
"type" : "destination"
}
]
}
I use SwiftyJSON and tries to get the superchargers latitude, longitude and name, like this:
let jsonName = json["superchargers"]["name"]
let jsonLat = json["superchargers"]["location"]["lat"]
let jsonLong = json["superchargers"]["location"]["long"]
When trying to print any of those, all of them return nil.
Any ideas what I am doing wrong, and how to do this?
The reason I want to do this is because I want to add them as annotation to a MKMapView.
The first error is that the JSON initializer you are using will create a single JSON string object, it will not parse the string as JSON data:
Instead of:
let json = JSON(nearbyChargingSites.jsonString!)
you need to use:
let json = JSON(data: dataFromJSONString)
Second you need to iterate over the superchargers array to collect all the values
Try something like:
if let dataFromString = nearbyChargingSites.jsonString!.data(using: .utf8, allowLossyConversion: false) {
let json = try! JSON(data: dataFromString,options: .allowFragments)
for supercharger in json["superchargers"].arrayValue {
let jsonName = supercharger["name"].stringValue
let jsonLat = supercharger["location"]["lat"].doubleValue
let jsonLong = supercharger["location"]["long"].doubleValue
}
}
Please note that the above code does not perform error handling and will crash if values are missing from JSON.
How I can get nearby location from Google SDK in iOS and Swift? I need all nearby places without any type and category?
Client don't want use this url: https://maps.googleapis.com/maps/api/place/search/json?location=lat,long&radius=1000&sensor=true&key=key
You can simply do this with this API call:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=51.226531,4.190688&destinations=51.114476,4.139618|51.148123,4.182590
There are three parameters in this URL,
JSON is used to return the response
origins contain the long and lat of the current location of the user and
destination contains all the addresses form which you want to find the nearest distance. the addresses will be in long and lat format and are separated by "|".
The response will be as follow
{
"destination_addresses" : [
"Dorpstraat 70, 9140 Temse, België",
"Eigenlostraat 38, 9100 Sint-Niklaas, België"
],
"origin_addresses" : [ "Provinciale Baan 37, 9120 Beveren, België" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "16,3 km",
"value" : 16346
},
"duration" : {
"text" : "22 min.",
"value" : 1321
},
"status" : "OK"
},
{
"distance" : {
"text" : "10,5 km",
"value" : 10521
},
"duration" : {
"text" : "17 min.",
"value" : 1003
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
All you have to do is to get the nearest destination on the time basis .
Cheers
Is it possible to create Salesreceipt without product/service value through QBO API? I have tried through API but it's not reflecting rate value and storing description value only.
If I remove ItemRef attribute(in request body) then it's reflecting rate and amount values and it's assigning some default and random product/service.
It is possible directly in QBO UI.
Request body where only description value storing:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"ItemRef" : { },
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
Request body where default product/service assigning:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
No.
QuickBooks Online does not support this.
I generate one passbook using this gem in rails and it seen that works but when I open the passbook .pkpass file I see this message:
It's in spanish but basically it says that this card isn't valid anymore.
Here is my JSON:
{
"formatVersion" : 1,
"passTypeIdentifier" : "{MY PASS ID HERE}",
"serialNumber" : "E5982H-I2",
"teamIdentifier" : "{MY TEAM ID HERE}",
"webServiceURL" : "https://example.com/passes/",
"authenticationToken" : "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
"barcode" : {
"message" : "123456789",
"format" : "PKBarcodeFormatPDF417",
"messageEncoding" : "iso-8859-1"
},
"locations" : [
{
"longitude" : -122.3748889,
"latitude" : 37.6189722
},
{
"longitude" : -122.03118,
"latitude" : 37.33182
}
],
"organizationName" : "CROCANTICKETS SL",
"description" : "Paw Planet Coupon",
"logoText" : "Paw Planet",
"foregroundColor" : "rgb(255, 255, 255)",
"backgroundColor" : "#FF4B33",
"coupon" : {
"primaryFields" : [
{
"key" : "offer",
"label" : "Any premium dog food",
"value" : "20% off"
}
],
"auxiliaryFields" : [
{
"key" : "expires",
"label" : "EXPIRES",
"value" : "2016-04-24T10:00-05:00",
"isRelative" : true,
"dateStyle" : "PKDateStyleShort"
}
]
}
}
Any idea? Thanks!
According to the Expiration Keys in the Passbook Package Format Reference check the expirationDate and voided keys. Since you do not have those in your JSON, it might be added by the gem you are using.
I have Coordinate model with many markers embedded_in User model. How to extract attributes without _ids so that on output display only each lng and lat?
structure:
{ "_id" : ObjectId( "4e9f418f1e7bf20fbc000009" ),
"name" : "test",
"coordinates" : [
{ "lng" : 16.86783310009764,
"lat" : 52.38353842845282,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000a" ) },
{ "lng" : 16.85787674023436,
"lat" : 52.40972501601293,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000b" ) },
{ "lng" : 16.92276474072264,
"lat" : 52.40071858320756,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000c" ) },
{ "lng" : 16.90182205273436,
"lat" : 52.38270020105396,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000d" ) },
{ "lng" : 16.96705337597655,
"lat" : 52.410661698108,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000e" ) },
{ "lng" : 16.89495559765624,
"lat" : 52.42773236584494,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000f" ) } ] }
e.g.
= debug #user.coordinates.to_json
gives:
--- ! '[{"_id":"4e9f418f1e7bf20fbc00000a","lat":52.383538428452816,"lng":16.86783310009764},{"_id":"4e9f418f1e7bf20fbc00000b","lat":52.40972501601293,"lng":16.85787674023436},{"_id":"4e9f418f1e7bf20fbc00000c","lat":52.40071858320756,"lng":16.92276474072264},{"_id":"4e9f418f1e7bf20fbc00000d","lat":52.382700201053964,"lng":16.90182205273436},{"_id":"4e9f418f1e7bf20fbc00000e","lat":52.410661698108,"lng":16.967053375976548},{"_id":"4e9f418f1e7bf20fbc00000f","lat":52.42773236584494,"lng":16.894955597656235}]'
expected:
--- ! '[{"lat":52.383538428452816,"lng":16.86783310009764},{"lat":52.40972501601293,"lng":16.85787674023436},{"lat":52.40071858320756,"lng":16.92276474072264},{"lat":52.382700201053964,"lng":16.90182205273436},{"lat":52.410661698108,"lng":16.967053375976548},{"lat":52.42773236584494,"lng":16.894955597656235}]'
Try using except
#user.coordinates.to_json(:except => '_id')
the accepted answer returns data you wished. I would suggest though to use without against mongoid query so you actually do not fetch the data from DB, which is ideal.
#user.coordinates.without('_id').to_json(:except => '_id')