Click here to Skip to main content
13,097,230 members (62,545 online)
Rate this:
Please Sign up or sign in to vote.
Was hoping someone could point me in the right direction for a problem i cant seem to find the answer for - I have a googlemaps jquery inside an mvc view that plots a postcode on a map. I want to pass postcodes from my model and show multiple markers on the google map. All the examples i find are for cshtml and have a for each item in model loop to add the markers. This methodology doesnt seem to work in vbhtml ( Razor ). Attached is my view and the model just passes and Id key field and a postcode ( pcode) :

how do I pass my model.pcode in a loop to the 'var postcode' inside the javascript. I read that you can point the maps to a controller/action but when i tried this the view returns the data to the view as a long xml style string and doesnt plot the points???

Thanks in advance


@ModelType IEnumerable(Of Maps_Application.Tbl_Pcodes)
    ViewData("Title") = "Index"
End Code
<pre lang="text"><pre lang="text"><pre lang="HTML">

<!DOCTYPE html>
<script src="" type="text/javascript"></script>
<div id="map_canvas" style="width: 600px; height: 800px;"></div>

<script type="text/javascript">

var postcode = "ln5 7nq";


<script type="text/javascript">
var geocoder;
var map;

$(document).ready(function () {

function initializeGoogleMap() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map($("#map_canvas")[0], myOptions);

function codeAddress() {
var address = postcode + ", UK";
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
} else {
alert("Geocode was not successful for the following reason: " + status);

Posted 30-May-13 23:16pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 31 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100