0
私はこのプロジェクトを介してGoogleのリバースジオコーディングAPIをヒットしたときにこのjsonオブジェクトを取得しました...しかし、問題は "結果"配列の下にある "form_address"しかし、それを行う方法を知らない。親切に私を助けてください。私はプログラミングで新鮮です。今どのように私はこのコントローラコードからのビューで地図を表示します..私はリストオブジェクト "販売"で緯度と経度を持って..また、私はGoogleのAPIから取得する場所があります。逆ジオコーディング(緯度と経度でアドレスを生成する)
{
"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"
}
私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);
がクリックより良い結果を見ることの
results[0].formatted_address
によってformatted_addressを得ることができますあなたはスニペットを実行しています –t hanx alot bro。 –
bt私はコントローラを介して逆ジオメトリAPIを呼び出しています。そして、ビュー内にマップを表示しなければなりません。 –