Exact
Exact

Reputation: 269

How to show a dynamic location in ASP MVC using Google Maps

I am developing an ASP MVC web application.

I am trying to show a location in a Google Maps frame according to a given address by the user (In a input field).

I wrote a Javascript function in order to show the location using the ASP Helpers Maps but it doesn't work.

This is what I've tried :

<div class="phone_email phone_email1" style="text-align:left;float:left;">
 <label>ADDRESS : </label>
   <div class="form-text">
     <i class="fa fa-map-marker" aria-hidden="true"></i>
       <form method="post">
        <input type="text" name="address" placeholder="Your Address" required="" style="margin-top:0px; width:506px;" value="@Request["address"]">
         <input type="submit" value="Map It!" />
       </form>
      </div>
 </div>
 <script>
  @if (IsPost)
   {
    @Maps.GetGoogleHtml(Request.Form["address"],
     width: "400",
     height: "400")
    }
 </script>

Upvotes: 1

Views: 1259

Answers (1)

AlexB
AlexB

Reputation: 7416

You shouldn't use these helpers, and follow the documentation

It's as easy as an API call : Just use

https://maps.googleapis.com/maps/api/geocode/json?address=YOUR_TEXTBOX_ADRESS&key=YOUR_API_KEY

To get the API_KEY, just follow the steps here
And replace YOUR_TEXTBOX_ADRESS by the adress entered by user

Upvotes: 1

Related Questions