Ich habe dieses JSON-Objekt, wenn ich die Google Reverse Geocodierung API durch mein Projekt .. Aber Problem ist, dass ich brauche nur "Formular_Adresse" Teil, der unter "Ergebnisse" -Array ist, aber nicht wissen, wie man das macht.gut mir helfen. Ich bin frisch in Programmierung .. Jetzt Wie werde ich Karte in Sicht von diesem Controller-Code .. Ich habe Breiten- und Längengrad in Liste Objekt "Verkauf" .. und auch ich habe Standort, die ich von Google API.Reverse Geocoding (Adresse durch Breiten- und Längengrad erzeugen)
{
"results" : [
{
"address_components" : [
{
"long_name" : "A-202",
"short_name" : "A-202",
"types" : [ "street_number" ]
},
{
"long_name" : "Western Express Highway",
"short_name" : "Western Express Hwy",
"types" : [ "route" ]
},
{
"long_name" : "Chinchpada",
"short_name" : "Chinchpada",
"types" : [ "political", "sublocality", "sublocality_level_2" ]
},
{
"long_name" : "Borivali East",
"short_name" : "Borivali East",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Mumbai",
"short_name" : "Mumbai",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Mumbai Suburban",
"short_name" : "Mumbai Suburban",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Maharashtra",
"short_name" : "MH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "400066",
"short_name" : "400066",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "A-202, Western Express Hwy, Chinchpada, Borivali East, Mumbai, Maharashtra 400066, India",
"geometry" : {
"location" : {
"lat" : 19.2186167,
"lng" : 72.86424029999999
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 19.2199656802915,
"lng" : 72.86558928029149
},
"southwest" : {
"lat" : 19.2172677197085,
"lng" : 72.86289131970848
}
}
},
"place_id" : "ChIJEfow2tGw5zsRl3X0IN7Nu7Y",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
mein controllercode.cs
public ActionResult Index()
{
List<salepros> sale = new List<salepros>();
string sqlquery = "select prospectid,latitude, longitude, location from sale_prospectdet where createdby = {0} order by createdon desc";
sqlquery = string.Format(sqlquery, "*");
DataTable dt = DbHelper.ExecuteDataset(Globals.GetConnectionString(), CommandType.Text, sqlquery).Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
salepros saleobject = new salepros();
string conditionLoc = Convert.ToString(dt.Rows[i]["location"]);
string conditionLat = Convert.ToString(dt.Rows[i]["latitude"].ToString());
string conditionLong = Convert.ToString(dt.Rows[i]["latitude"].ToString());
if (conditionLat == "" && conditionLong == "")
{
saleobject.latitude = "";
saleobject.longitude = "";
saleobject.Location = "No Location Found";
}
else if (conditionLoc == "")
{
saleobject.latitude = Convert.ToString(dt.Rows[i]["latitude"].ToString());
saleobject.longitude = Convert.ToString(dt.Rows[i]["longitude"].ToString());
saleobject.prospectdetid = Convert.ToInt32(dt.Rows[i]["prospectdetid"]);
string apiurl = string.Format("https://maps.googleapis.com/maps/api/geocode/json?key=mykey&latlng=" + saleobject.latitude + "," + saleobject.longitude);
string strresponse = CommonFunctions.GetResponse(apiurl, "Get", null, null);
JSONClass jsonclass = JsonConvert.DeserializeObject<JSONClass>(strresponse);
if (jsonclass.status == "ZERO_RESULTS")
{
saleobject.Location = "No Location Found";
}
else
{
saleobject.Location = jsonclass.results[0].formatted_address;
string locationquery = "UPDATE `sale_prospectdet` SET `location`='{0}' WHERE `prospectdetid`={1}";
locationquery = string.Format(locationquery, saleobject.Location, saleobject.prospectdetid);
int rowsaffected = DbHelper.ExecuteNonQuery(Globals.GetConnectionString(), CommandType.Text, locationquery);
}
}
else
{
saleobject.latitude = Convert.ToString(dt.Rows[i]["latitude"].ToString());
saleobject.longitude = Convert.ToString(dt.Rows[i]["longitude"].ToString());
saleobject.Location = Convert.ToString(dt.Rows[i]["location"]);
}
sale.Add(saleobject);
}
return View("Location", sale);
Klick auf volle Seite bekommen besseres Ergebnis zu sehen, wenn Sie führen Snippet –
t hanx viel bro. –
bt Ich rufe Reverse Geodierung API durch meine Steuerung und dann muss ich Karte in Sicht anzeigen .. –